2

I have tried to integrate between Shelly and Telegram.

In Telegram there is an option called webhook that mean , if Telegram bot received an message that message will automatically move to another server :

To open my Shelly relay I can send a POST ( doc ):

curl -X POST https://shelly-54-eu.shelly.cloud/device/relay/control -d "channel=0&turn=on&id=<Shelly_id>&auth_key=<Shelly_auth_key>"

I tried to implement with wehbook a redirection for Shelly cloud , so when my telegram bot received an message my Shelly will open the relay.

I have tried set set the webhook like that :

curl -X POST https://api.telegram.org/bot<telegam_bot_token>/setWebhook --data-urlencode "url=https://shelly-54-eu.shelly.cloud/device/relay/control?channel=0&turn=on&id=<Shelly_id>&auth_key=<Shelly_auth_key>"

But When I watch at getWebhookInfo URL : https://api.telegram.org/bot<Tlegram_token>/getWebhookInfo: I saw :

{"ok":true,"result":{"url":"https://shelly-54-eu.shelly.cloud/device/relay/control?channel=0&turn=on&id=<Shelly_id>&auth_key=<Shelly_auth_key>","has_custom_certificate":false,"pending_update_count":5,"last_error_date":1670102630,"last_error_message":"Wrong response from the webhook: 401 Unauthorized","max_connections":40,"ip_address":"<Shelly_ip>"}}

.

If I replace --data-urlencode with -d :

curl -X POST https://api.telegram.org/bot<telegam_bot_token>/setWebhook -d "url=https://shelly-54-eu.shelly.cloud/device/relay/control?channel=0&turn=on&id=<Shelly_id>&auth_key=<Shelly_auth_key>"

So https://api.telegram.org/bot<Tlegram_token>/getWebhookInfo return

{"ok":true,"result":{"url":"https://shelly-54-eu.shelly.cloud/device/relay/control?channel=0","has_custom_certificate":false,"pending_update_count":1,"last_error_date":1670263360,"last_error_message":"Wrong response from the webhook: 401 Unauthorized","max_connections":40,"ip_address":"<Shelly_ip>"}}

Apparently the problem is that Shelly server expected to get channel=0&turn=on&id=<Shelly_id>&auth_key=<Shelly_auth_key> as "data" and not through URL ,

Is there any way to pass this data using Telegram webhook?

vtable
  • 302
  • 2
  • 15
  • I don't think the problem is with Shelly server expecting the parameters in data and not in url. The response from the `getWebhookInfo` method clearly tells you that the server returned `401 Unauthorized` response, which means parameters may be not correct. Are `auth_key`, `id` and `channel` correct? Did you test it outside of Telegram? – druskacik Dec 05 '22 at 13:11
  • Wait, I may be wrong. The way to test where is the problem, you can use `curl` to communicate with the shelly server using two different commands. Try to use curl with `-d` flag and then with `--data-urlencode` flag. If `-d` gives you success response and `--data-urlencode` gives you error response, you'll know that shelly expects data as "form data" and not in url. Which, I am afraid, Telegram webhook can't do. – druskacik Dec 05 '22 at 13:20
  • @druskacik I have update my post with how I replaced `--data-urlencode` with `-d` – vtable Dec 05 '22 at 18:07
  • I meant, try to use `curl` to communicate with shelly server, with `-d` flag and then with `--data-urlencode` flag. Does `curl -X POST https://shelly-54-eu.shelly.cloud/device/relay/control --data-urlencode "channel=0&turn=on&id=&auth_key="` work? If not, shelly can't parse arguments from the url. – druskacik Dec 07 '22 at 09:39

0 Answers0