Integrate between Shelly and Telegram via Webhook

794 Views Asked by At

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?

0

There are 0 best solutions below