Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telegram response to bot is truncated #10486

Closed
13 of 14 tasks
ajithvasudevan opened this issue Jan 10, 2021 · 33 comments
Closed
13 of 14 tasks

Telegram response to bot is truncated #10486

ajithvasudevan opened this issue Jan 10, 2021 · 33 comments
Assignees
Labels
bug Type - Confirmated Bug fixed Result - The work on the issue has ended

Comments

@ajithvasudevan
Copy link

PROBLEM DESCRIPTION

A clear and concise description of what the problem is.
Tasmota's Telegram response is truncated as viewed in the Telegram mobile app.

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

  • Read the Contributing Guide and Policy and the Code of Conduct
  • Searched the problem in issues
  • Searched the problem in discussions
  • Searched the problem in the docs
  • Searched the problem in the chat
  • Device used (e.g., Sonoff Basic): Wemos D1 Mini
  • Tasmota binary firmware version number used: 9.2.0
    • Pre-compiled
    • Self-compiled
  • Flashing tools used: Tasmotizer 1.2.1
  • Provide the output of command: Backlog Template; Module; GPIO 255:
  Configuration output here:
12:55:02 CMD: Backlog Template; Module; GPIO 255
12:55:02 RSL: RESULT = {"NAME":"Generic","GPIO":[1,1,1,1,1,1,1,1,1,1,1,1,1,1],"FLAG":0,"BASE":18}
12:55:02 RSL: RESULT = {"Module":{"18":"Generic"}}
12:55:02 RSL: RESULT = {"GPIO0":{"0":"None"},"GPIO1":{"0":"None"},"GPIO2":{"0":"None"},"GPIO3":{"0":"None"},"GPIO4":{"640":"I2C SDA"},"GPIO5":{"608":"I2C SCL"},"GPIO9":{"0":"None"},"GPIO10":{"0":"None"},"GPIO12":{"0":"None"},"GPIO13":{"224":"Relay1"},"GPIO14":{"160":"Switch1"},"GPIO15":{"0":"None"},"GPIO16":{"0":"None"},"GPIO17":{"0":"None"}}}
  • If using rules, provide the output of this command: Backlog Rule1; Rule2; Rule3:
  Rules output here:
12:55:51 CMD: rule1
12:55:51 RSL: RESULT = {"Rule1":"ON","Once":"OFF","StopOnError":"OFF","Length":115,"Free":396,"Rules":"on system#boot do backlog IPAddress1 endon on IPAddress1#data do backlog tmstate 1; tmstate 3; tmsend %value% endon"}
12:55:52 CMD: rule2
12:55:52 RSL: RESULT = {"Rule2":"ON","Once":"OFF","StopOnError":"OFF","Length":115,"Free":396,"Rules":"on power1#state=1 do  tmsend Porch Light Turned ON endon on power1#state=0 do  tmsend Porch Light Turned OFF endon "}
12:55:54 CMD: rule3
12:55:54 RSL: RESULT = {"Rule3":"OFF","Once":"OFF","StopOnError":"OFF","Length":36,"Free":475,"Rules":"on power1#state=1 do power2 on endon"}
  • Provide the output of this command: Status 0:
  STATUS 0 output here:
12:39:13 SRC: WebConsole from 172.20.1.2
12:39:13 CMD: Group 0, Index 1, Command "STATUS", Data "0"
12:39:13 RSL: STATUS = {"Status":{"Module":18,"DeviceName":"timer","FriendlyName":["timer"],"Topic":"timer","ButtonTopic":"0","Power":1,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0}}
12:39:13 RSL: STATUS1 = {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota/release/tasmota.bin.gz","RestartReason":"External System","Uptime":"0T00:03:39","StartupUTC":"2021-01-10T07:05:34","Sleep":50,"CfgHolder":4617,"BootCount":6,"BCResetTime":"2021-01-09T22:35:39","SaveCount":39,"SaveAddress":"3F4000"}}
12:39:13 RSL: STATUS2 = {"StatusFWR":{"Version":"9.2.0(tasmota)","BuildDateTime":"2021-01-09T16:00:25","Boot":31,"Core":"2_7_4_9","SDK":"2.2.2-dev(38a443e)","CpuFrequency":160,"Hardware":"ESP8266EX","CR":"430/699"}}
12:39:13 RSL: STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":4,"MqttLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["Andromeda","tsvk24"],"TelePeriod":0,"Resolution":"558180C0","SetOption":["0000A003","2805C8000100060000005A00000000000000","00000021","00006000","00000000"]}}
12:39:13 RSL: STATUS4 = {"StatusMEM":{"ProgramSize":750,"Free":2320,"Heap":16,"ProgramFlashSize":4096,"FlashSize":4096,"FlashChipId":"164020","FlashFrequency":40,"FlashMode":3,"Features":["00000809","0FAEE596","04260081","000000C3","00000400","C000F981","00008024","00001000"],"Drivers":"1,2,4,5,6,8,9,10,13,18,19,22,24,26,27,29,30,35,37,40,45","Sensors":"1,2,4,5,6,33"}}
12:39:13 RSL: STATUS5 = {"StatusNET":{"Hostname":"porchtimer","IPAddress":"172.20.1.52","Gateway":"172.20.1.1","Subnetmask":"255.255.255.0","DNSServer":"172.20.1.1","Mac":"48:3F:DA:xx:xx:xx","Webserver":2,"WifiConfig":4,"WifiPower":17.0}}
12:39:13 RSL: STATUS7 = {"StatusTIM":{"UTC":"2021-01-10T07:09:13","Local":"2021-01-10T12:39:13","StartDST":"2021-03-28T02:00:00","EndDST":"2021-10-31T03:00:00","Timezone":"+05:30","Sunrise":"06:45","Sunset":"18:12"}}
12:39:13 RSL: STATUS10 = {"StatusSNS":{"Time":"2021-01-10T12:39:13","Switch1":"ON"}}
12:39:13 RSL: STATUS11 = {"StatusSTS":{"Time":"2021-01-10T12:39:13","Uptime":"0T00:03:39","UptimeSec":219,"Heap":16,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":32,"MqttCount":0,"POWER":"ON","Wifi":{"AP":1,"SSId":"Andromeda","BSSId":"00:11:32:xx:xx:xx","Channel":5,"RSSI":100,"Signal":-34,"LinkCount":1,"Downtime":"0T00:00:03"}}}

  • Set weblog to 4 and then, when you experience your issue, provide the output of the Console log:
  Console output here:
12:35:53 TGM: getUpdates
12:35:55 TGM: Response {"ok":true,"result":[]}
12:36:02 WIF: Checking connection...
12:36:02 DNS: MDNS.update
12:36:07 TGM: getUpdates
12:36:09 TGM: Response {"ok":true,"result":[]}
12:36:20 TGM: getUpdates
12:36:22 TGM: Response {"ok":true,"result":[{"update_id":75814xxxx,
"message":{"message_id":204,"from":{"id":xxxxxxxxxx,"is_bot":false,"first_name":"Ajith","username":"xxxxxxxx","language_code":"en"},"chat":{"id":xxxxxxxxxx,"first_name":"Ajith","username":"xxxxxxxx","type":"private"},"date":1610262370,"text":"Rule3"}}]}
12:36:22 TGM: Parsed update_id xxxxxxxxx, chat_id xxxxxxxxxx, text "Rule3"
12:36:22 SRC: Chat
12:36:22 CMD: Group 0, Index 3, Command "RULE", Data ""
12:36:22 RSL: RESULT = {"Rule3":"OFF","Once":"OFF","StopOnError":"OFF","Length":36,"Free":475,"Rules":"on power1#state=1 do power2 on endon"}
12:36:22 TGM: sendMessage
12:36:27 WIF: Checking connection...
12:36:27 DNS: MDNS.update
12:36:34 TGM: getUpdates
12:36:35 TGM: Response {"ok":true,"result":[]}

TO REPRODUCE

Steps to reproduce the behavior:
After building Tasmota 9.2.0 with Telegram support, set it up with token and chatid, and confirm that messages can be sent both ways.

Setup a simple rule such as "Rule3 on power1#state=1 do power2 on endon".

Now send the message "Rule3" from Telegram (bot) on mobile phone.

See that the response message received in the mobile after a couple seconds is truncated, like -

{"Rule3":"OFF","Once":"OFF","StopOnError":"OFF","Length":36,"Free":475,"Rules":"on power1

EXPECTED BEHAVIOUR

A clear and concise description of what you expected to happen.
The response received should be complete, for example,

{"Rule3":"OFF","Once":"OFF","StopOnError":"OFF","Length":36,"Free":475,"Rules":"on power1#state=1 do power2 on endon"}

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

ADDITIONAL CONTEXT

Add any other context about the problem here.

(Please, remember to close the issue when the problem has been addressed)

@ascillato2 ascillato2 added the troubleshooting Type - Troubleshooting label Jan 10, 2021
@sfromis
Copy link
Contributor

sfromis commented Jan 10, 2021

What you posted in https://discord.com/channels/479389167382691863/490244847568158751/797881187636609035 is concistent with some tool "on the way" cutting off the string at the # character, not too unusual as a delimiter. Did you check the actual MQTT message emanating from Tasmota?

@ajithvasudevan
Copy link
Author

ajithvasudevan commented Jan 10, 2021

The "on the way" tool I used, and the screenshot I provided happens to be the official Telegram app (Android).

MQTT has nothing to do with my usage of Telegram because, as mentioned above in the "TO REPRODUCE" section, I built Tasmota 9.2.0 with Telegram support and am relying on the builtin support for Telegram in Tasmota for sending a Telegram message directly from the Tasmota console or receiving in my mobile phone a message as a response from Tasmota.
Do you want me to test anything else?

@ajithvasudevan
Copy link
Author

ajithvasudevan commented Jan 10, 2021

Findings from discussion here: https://discord.com/channels/479389167382691863/490244847568158751/797897053921345607

It seems the Tasmota command -

tmsend test1test1test1test1test1 # test22222222 #test33333333

causes the truncated message

test1test1test1test1test1

to be received in Telegram

and the command -

tmsend test1test1test1test1test1 %23 test22222222%23test33333333

causes

tmsend test1test1test1test1test1 # test22222222#test33333333

to be received.

In the latter case, the "#" has been URLEncoded in the command, and the message received is the expected message.

This leads me to believe that the Telegram API call from the Tasmota Telegram Driver is currently not being URLEncoded, and some special characters in the query parameters of the Telegram API could cause it to lose information or fail.

@arendst arendst self-assigned this Jan 11, 2021
arendst added a commit that referenced this issue Jan 11, 2021
Fix telegram response using UrlEncode (#10486)
@arendst
Copy link
Owner

arendst commented Jan 11, 2021

Thx for providing the needed information.

Latest development commit adds UrlEncode to any text send from Tasmota to Telegram.

Pls try.

BTW Nice rule1 usage!!!

@arendst arendst added bug Type - Confirmated Bug fixed Result - The work on the issue has ended and removed troubleshooting Type - Troubleshooting labels Jan 11, 2021
@ajithvasudevan
Copy link
Author

Thx for providing the needed information.

Latest development commit adds UrlEncode to any text send from Tasmota to Telegram.

Pls try.

Tried it, and it works as expected, as seen in the screen-shot below from the Telegram app on my mobile phone. No truncation!
image

BTW Nice rule1 usage!!!

Thanks!

@ajithvasudevan
Copy link
Author

ajithvasudevan commented Jan 11, 2021

Closing the issue as it is fixed. :-)

@SHA-NDY
Copy link

SHA-NDY commented Feb 17, 2021

May I ask which defines have to be added before compiling to get telegram functionality and is there a doc?

@ajithvasudevan
Copy link
Author

ajithvasudevan commented Feb 18, 2021

#define USE_TELEGRAM

There's no official doc yet, AFAIK. I found this #8619 and then I looked through the source-code to figure it out :)

EDIT: here's some documentation: #8619 (comment)

@SHA-NDY
Copy link

SHA-NDY commented Feb 18, 2021

#define USE_TELEGRAM

There's no official doc yet, AFAIK. I found this #8619 and then I looked through the source-code to figure it out :)

EDIT: here's some documentation: #8619 (comment)

Thank you very much! Tasmota rocks!

@SHA-NDY
Copy link

SHA-NDY commented Feb 18, 2021

#define USE_TELEGRAM

There's no official doc yet, AFAIK. I found this #8619 and then I looked through the source-code to figure it out :)

EDIT: here's some documentation: #8619 (comment)

Do you know if this works in Tasmota32 or how I can find out if it works? I'm new in the Tasmota-Universe and didn't dive deep into it by now

@ajithvasudevan
Copy link
Author

ajithvasudevan commented Feb 18, 2021

Do you know if this works in Tasmota32 or how I can find out if it works? I'm new in the Tasmota-Universe and didn't dive deep into it by now

Yes, it does. A sure way to find out is to flash it on your device and try it. I just did :)

Once flashed, you need to setup your telegram token and chat id with two commands (from web-console or MQTT):

TmToken <token> // <token> is without the "bot" prefix (didn't work with the prefix)
TmChatId <chat_id> // <chat_id> is your telegram Chat ID

Next, you will have to enable Telegram Send/Receive with the TmState command:

TmState <state> // <state> can be 0 to 5

  • TmState 0 - Disable telegram sending (default)
  • TmState 1 - Enable telegram sending (needs valid TmChatId)
  • TmState 2 - Disable telegram listener (default)
  • TmState 3 - Enable telegram listener
  • TmState 4 - Disable telegram response echo (default)
  • TmState 5 - Enable telegram response echo

@SHA-NDY
Copy link

SHA-NDY commented Feb 18, 2021

Thanks a lot

@SHA-NDY
Copy link

SHA-NDY commented Feb 19, 2021

Would be nice to have Telegram functionality on tasmota32-webcam builds to send pictures. I found several examples for arduino so it should be possible...where would be the right place to communicate a feature request?

@ascillato
Copy link
Contributor

ascillato commented Feb 19, 2021

Feature requests should go to Ideas in Discussions. Thanks.

@supperka
Copy link

Hello , I can send info from tasmota to telegram, but not from telegram to tasmota.
what can be wrong? Telegram just reply my msg. Tmstate are {"TmState":{"Send":"ON","Receive":"ON","Echo":"ON"}}

@SHA-NDY
Copy link

SHA-NDY commented Feb 23, 2021

Hello , I can send info from tasmota to telegram, but not from telegram to tasmota.
what can be wrong? Telegram just reply my msg. Tmstate are {"TmState":{"Send":"ON","Receive":"ON","Echo":"ON"}}

Which command did you send? You can send Tasmota commands like "Power1 1"

@supperka
Copy link

Hello , I can send info from tasmota to telegram, but not from telegram to tasmota.
what can be wrong? Telegram just reply my msg. Tmstate are {"TmState":{"Send":"ON","Receive":"ON","Echo":"ON"}}

Which command did you send? You can send Tasmota commands like "Power1 1"

Yes I tried rule1 , power1 1 but nothing .From Tasmota command tmsend works fine without problems

@SHA-NDY
Copy link

SHA-NDY commented Feb 23, 2021

Is your ChatId correct? Perhaps Tasmota filters commands from unauthorized (unknown) ChatIDs

@supperka
Copy link

Is your ChatId correct? Perhaps Tasmota filters commands from unauthorized (unknown) ChatIDs

I tried change last numbers of my chatid and still getting messages from Tasmota so maybe is that problem. How can easily get chatid?

@SHA-NDY
Copy link

SHA-NDY commented Feb 23, 2021

Search for "IDBot" in Telegram and start a conversation with the bot. Type "/getid" to get your ChatID and enter it in Tasmota

@supperka
Copy link

Thank you , so my chatid is correct! 🙄

@SHA-NDY
Copy link

SHA-NDY commented Feb 23, 2021

Thank you , so my chatid is correct! 🙄

I just saw it. You have to disable ECHO --> {"TmState":{"Send":"ON","Receive":"ON","Echo":"OFF"}} --> TmState 4

@supperka
Copy link

Hello, my telegram integration stopped working on all tasmota devices two days ago. Before was all fine , i didn't get any update or setting. I'm only one with this problem?
If I try tmsend xxx got send failed , I tried revoke token or reset tmstate but without success.

@s-hadinger
Copy link
Collaborator

Any logs?

@ajithvasudevan
Copy link
Author

ajithvasudevan commented Jun 23, 2021

Any logs?

I confirm it stopped working.
Setting weblog 4 and trying to send did not result in any logs, though:

09:04:13.940 MQT: stat/BELL/RESULT = {"WebLog":4}
09:04:13.025 CFG: Saved to flash at 3F9, Count 186, Bytes 4096
09:04:19.189 WIF: Checking connection...
09:04:25.695 CMD: tmsend test
09:04:25.696 SRC: WebConsole from 172.20.1.2
09:04:25.698 CMD: Group 0, Index 1, Command "TMSEND", Data "test"
09:04:25.700 TGM: sendMessage
09:04:27.098 MQT: stat/BELL/RESULT = {"TmSend":"Failed"}
09:04:40.636 WIF: Checking connection...

tmToken and tmChatId are set to correct values, and tmState is {"TmState":{"Send":"ON","Receive":"OFF","Echo":"OFF"}}

Is there something else I can try?

PS: Using Tasmota 9.3.1.2

@ajithvasudevan
Copy link
Author

I printed a part of the response from the call to Telegram API (sendMessage) in the telegram driver, and this is what I got:

06:42:18.831 TGM: response = <!DOCTYPE html>
<html class="">
  <head>
    <meta charset="utf-8">
    <title>sendMessage</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta property="description" content="">
    <meta property="og:title" content="sendMessage">
    <meta property="og:image" content="">
    <meta property="og:description" content="">
    <link rel="shortcut icon" href="/favicon.ico?4" type="image/x-icon" />

    <link href="/css/bootstrap.min.css?3" rel="stylesheet">
    
    <link href="/css/telegram.css?212" rel="stylesheet" media="screen">
    <style>
    </style>
  </head>
  <body class="preload">
    <div class="dev_page_wrap">
      <div class
06:42:18.841 RSL: stat/tasmota_74E359/RESULT = {"TmSend":"Failed"}

Shouldn't this be a JSON instead of HTML ?

@s-hadinger
Copy link
Collaborator

Yes indeed, it should be JSON. Maybe the API requires an additional parameter to force JSON

@ajithvasudevan
Copy link
Author

ajithvasudevan commented Jun 23, 2021

Yes indeed, it should be JSON. Maybe the API requires an additional parameter to force JSON

The API works if you try the same URL that is being called from Tasmota (https://api.telegram.org/bot[token]/sendMessage?chat_id=[chatId]&text=test), from a browser. So additional parameter doesn't seem to be the issue.

@sfromis
Copy link
Contributor

sfromis commented Jun 23, 2021

Maybe the HTML contains some error message indicating a failure before even coming to the API. I've seen such from other web services unable to execute a call I posted.

@ajithvasudevan
Copy link
Author

ajithvasudevan commented Jun 23, 2021

Maybe the HTML contains some error message indicating a failure before even coming to the API. I've seen such from other web services unable to execute a call I posted.

I have added a screen-shot of the complete HTML in the issue I raised, here: #12451

@sfromis
Copy link
Contributor

sfromis commented Jun 23, 2021

That indeed looks like a generic message page instead of API output. May be an error on the Telegram end.

@ajithvasudevan
Copy link
Author

That indeed looks like a generic message page instead of API output. May be an error on the Telegram end.

The error should then appear even when calling the Telegram API GET request from the browser. However, it works fine if you hit the URL https://api.telegram.org/bot[token]/sendMessage?chat_id=[chatId]&text=test) from a browser, or even a curl of the same URL. You get JSON response in both cases. As far as I can tell, Tasmota's telegram driver too calls the same URL using BearSSL lib. I verified the URL it calls. It is the same as the one which works from the browser or curl.

@ajithvasudevan
Copy link
Author

Let's discuss further in issue #12451

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type - Confirmated Bug fixed Result - The work on the issue has ended
Projects
None yet
Development

No branches or pull requests

8 participants