windkh / node-red-contrib-telegrambot

Telegram bot nodes for node-red.
Other
256 stars 117 forks source link

Inline Query und Chatid #341

Closed averlon closed 8 months ago

averlon commented 8 months ago

Discussed in https://github.com/windkh/node-red-contrib-telegrambot/discussions/340

Originally posted by **averlon** October 18, 2023 Ich bitte um Unterstützung um eine Inline Query hinzubekommen. Meine Annahme: Soweit ich die Doku verstanden habe, kann ein Benutzer in irgendeinem Chat (Channel oder Group) mit "@botname command" eine Inline Query starten. In NodeRed wird das mit einem Event-Node vom Event "Inline Query" als Eingang aufgefangen. Ein Beispiel: ``` [ { "id": "45960b7d9cc584fd", "type": "telegram event", "z": "33667947.7eff86", "name": "", "bot": "f37b455ea89fd0ca", "event": "inline_query", "autoanswer": true, "x": 110, "y": 1320, "wires": [ [ "5ba32f5326eedc17", "c5b80a01a8cd4427" ] ] }, { "id": "5ba32f5326eedc17", "type": "debug", "z": "33667947.7eff86", "name": "av_tel inline_query", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 310, "y": 1280, "wires": [] }, { "id": "c5b80a01a8cd4427", "type": "change", "z": "33667947.7eff86", "name": "inline_query", "rules": [ { "t": "delete", "p": "payload", "pt": "msg" }, { "t": "set", "p": "payload", "pt": "msg", "to": "{}", "tot": "json" }, { "t": "set", "p": "payload.type", "pt": "msg", "to": "message", "tot": "str" }, { "t": "set", "p": "payload.chatId", "pt": "msg", "to": "-1001509670149", "tot": "num" }, { "t": "set", "p": "payload.content", "pt": "msg", "to": "Was ist gefragt?", "tot": "str" }, { "t": "set", "p": "payload.options.reply_markup", "pt": "msg", "to": "$string(\t {\t \"resize_keyboard\":true,\t \"one_time_keyboard\":true,\t \"inline_keyboard\":[\t [\t {\t \"text\": \"Hilfe alle Kommandos\",\t \"callback_data\": \"hilfe\" \t },\t {\t \"text\": \"Abonnenten anzeigen\",\t \"callback_data\": \"abo\" \t } \t ]\t ] \t } \t)", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 290, "y": 1320, "wires": [ [ "584fb6a9678bedb7", "5c4006e5b468f623" ] ] }, { "id": "584fb6a9678bedb7", "type": "telegram sender", "z": "33667947.7eff86", "name": "", "bot": "f37b455ea89fd0ca", "haserroroutput": false, "outputs": 1, "x": 550, "y": 1320, "wires": [ [] ] }, { "id": "f37b455ea89fd0ca", "type": "telegram bot", "botname": "averlon_bot", "usernames": "", "chatids": "", "baseapiurl": "", "updatemode": "polling", "pollinterval": "300", "usesocks": false, "sockshost": "", "socksprotocol": "socks5", "socksport": "6667", "socksusername": "anonymous", "sockspassword": "", "bothost": "", "botpath": "", "localbotport": "8443", "publicbotport": "8443", "privatekey": "", "certificate": "", "useselfsignedcertificate": false, "sslterminated": false, "verboselogging": false } ] ``` Der Debug vom Event zeigt: ``` { "payload": { "chatId": undefined, "type": "inline_query", "content": "", "inlineQueryId": "4213605307446235708", "offset": "", "from": { "id": 123456, "is_bot": false, "first_name": "Vorname", "last_name": "Nachname", "username": "username", "language_code": "de" } }, "originalMessage": { "id": "4213605307446235708", "from": { "id": 123456, "is_bot": false, "first_name": "Vorname", "last_name": "Nachname", "username": "username", "language_code": "de" }, "chat_type": "channel", "query": "", "offset": "" }, "_msgid": "c1a686e07c652caf" } ``` Jetzt ist die chatId des Channels oder der Group in dem die Inline Query abgesetzt wurde "undefinded". Wenn jetzt die Antwortmöglichkeiten geschickt werden, wohin sollen die denn gehen? Die Antwortmöglichkeiten sollen doch da erscheinen, wo die Inline Query angefordert wurde! An dieser Stelle bin ich etwas verloren! Kann mir hier jemand aufs Pferd helfen? Anmerkung: Ich konnte erfolgreich eine Inline Query erzeugen und senden, wenn der Event ein Command war. In diesem Fall wird über den command-node die chatId mitgeliefert. Danke Zusatzfrage: Was bewirkt der Schalter "Auto-Answer"?
averlon commented 8 months ago

Hallo Karl-Heinz, ich hatte das als Diskussion eingestellt. Da hat sich aber nichts getan! Eigentlich ist das ja (noch) kein Issue sondern eher eine Diskussion / Hilfestellung.

windkh commented 8 months ago

Kann ich mir am Wochenende anschauen

windkh commented 8 months ago

@averlon Zur Erklärung: ein inline_query braucht zur Beantwortung keine chat ID da eine inline_query_id erstellt wird. https://core.telegram.org/bots/api#answerinlinequery

Den Rest habe ich in der Discussion beschrieben