Send messages to Telegram

Hi,
I’m trying to send a message with Telegram, but it doesn’t work. I’m not sure what to put in the settings: I used the token from the one I created earlier and my phone number.
Thanks

Hi,
Did you follow the instructions here nymea-plugins/README.md at master · nymea/nymea-plugins · GitHub
?

I think so. I recreated a Bot, I can write him something with Telegram.
I get this as an error in the LOG “QNetworkReply::ProtocolInvalidOperationError”

Strange, I also have this type of error right after in the LOG, is it normal?

W | nymea.mqtt.client: MQTT socket error: QAbstractSocket::SocketError(20)
W | AWS: An error happened in the MQTT transport QAbstractSocket::SocketError(20)
W | AWS: Pairing failed: 401 “Unauthorized - Token invalid: jwt expired”
W | nymea.mqtt.client: MQTT socket error: QAbstractSocket::SocketError(20)
W | AWS: An error happened in the MQTT transport QAbstractSocket::SocketError(20)
W | AWS: Pairing failed: 401 “Unauthorized - Token invalid: jwt expired”

FYI: I have not activated MQTT.

This error in the log is unreated to the Telegram plugin. For some reason the connection to nymea:cloud drops occationally… I have seen the same today, sometimes AWS is a bit flaky but normally it recovers instantly.

Anyhow, for telegram, I just tried here… It seems to work fine. Perhaps enable more logging for the telegram plugin (System settings → Developer tools → open debug server → Logs) and try setting it up again…

Also please describe what exactly doesn’t work. You go to add new thing → Telegram → then it will ask you for the telegram bot token, enter it there and press next. it should present a list of all the channels/contacts that wrote to the bot recently. Picking one of them would create a new thing that allows messaging that particular contact or group.

MQTT is not needed for the telegram plugin.

If it doesn’t find anything when discovering, you can also try to open this URL in your browser. Replace <token> with your bot token.

https://api.telegram.org/bot<token>/getUpdates

It should return some JSON containing chat ids… If it does, but nymea doesn’t list anything there could be a bug in the plugin. Please show me that json in this case.

Oh, yes! Thank you very much for all these explanations. With

https://api.telegram.org/bot<token>/getUpdates

I got an ID and now it works! Thank you!

well, still sounds like there’s an issue somewhere… nymea really sould parse the getUpdates reply on its own and allow picking you from a list. Mind sharing the getUpdates response with me please so I can check if there’s something different for you?

{“ok”:true,“result”:[{“update_id”:211789454,
“message”:{“message_id”:3,“from”:{“id”:211096490,“is_bot”:false,“first_name”:“Michel”,“username”:“mfoucrier”,“language_code”:“fr”},“chat”:{“id”:211096490,“first_name”:“Michel”,“username”:“mfoucrier”,“type”:“private”},“date”:1617543474,“text”:"@Michel",“entities”:[{“offset”:0,“length”:7,“type”:“mention”}]}},{“update_id”:211789455,
“my_chat_member”:{“chat”:{“id”:-115730672,“title”:“EXC_general”,“type”:“group”,“all_members_are_administrators”:false},“from”:{“id”:211096490,“is_bot”:false,“first_name”:“Michel”,“username”:“mfoucrier”,“language_code”:“fr”},“date”:1617543527,“old_chat_member”:{“user”:{“id”:1702104174,“is_bot”:true,“first_name”:“MynymeaMSG”,“username”:“Mynymea_bot”},“status”:“left”},“new_chat_member”:{“user”:{“id”:1702104174,“is_bot”:true,“first_name”:“MynymeaMSG”,“username”:“Mynymea_bot”},“status”:“member”}}},{“update_id”:211789456,
“message”:{“message_id”:4,“from”:{“id”:211096490,“is_bot”:false,“first_name”:“Michel”,“username”:“mfoucrier”,“language_code”:“fr”},“chat”:{“id”:-115730672,“title”:“EXC_general”,“type”:“group”,“all_members_are_administrators”:false},“date”:1617543527,“new_chat_participant”:{“id”:1702104174,“is_bot”:true,“first_name”:“MynymeaMSG”,“username”:“Mynymea_bot”},“new_chat_member”:{“id”:1702104174,“is_bot”:true,“first_name”:“MynymeaMSG”,“username”:“Mynymea_bot”},“new_chat_members”:[{“id”:1702104174,“is_bot”:true,“first_name”:“MynymeaMSG”,“username”:“Mynymea_bot”}]}},{“update_id”:211789457,
“message”:{“message_id”:5,“from”:{“id”:211096490,“is_bot”:false,“first_name”:“Michel”,“username”:“mfoucrier”,“language_code”:“fr”},“chat”:{“id”:211096490,“first_name”:“Michel”,“username”:“mfoucrier”,“type”:“private”},“date”:1617543753,“text”:“Salut bot tu va bien ?”}}]}

Thanks @mfoucrier ,

strange, I’ve taken your json data and ran it through the code. It seems to work just fine. Well, there is one cosmetic bug which I’ve fixed, but I’m really not sure why the discovery during setup would not work for you…

I’ve also updated the README to provider more clear instructions: Telegram: Fix small cosmetic issue during setup and improve readme by mzanetti · Pull Request #412 · nymea/nymea-plugins · GitHub