Telegram bot setup without server

I am not very familiar with web technologies and would like to know if there is a way - the idea would be to use setWebhook - to make the telegram bot do simple things (how they simply repeat the same message again and again every time someone sends this message ) without configuring the server .

I think this may not be the case, because I need to parse the JSON object to force chat_id to send messages ... but I hope someone here can know the way.

eg.

https://api.telegram.org/bot<token>/setWebHook?url=https://api.telegram.org/bot<token>/sendMessage?text=Hello%26chat_id=<somehow get the chat_id> 

I tested it with a hardcoded chat id, and it works ... but of course, it will always send messages only to the same chat, no matter where it received the message.

+2
json webhooks telegram-bot
source share
2 answers

Here is a very simple example of Python bots, you can run this on your PC without the need for a server.

 import requests import json from time import sleep # This will mark the last update we've checked last_update = 0 # Here, insert the token BotFather gave you for your bot. token = 'YOUR_TOKEN_HERE' # This is the url for communicating with your bot url = 'https://api.telegram.org/bot%s/' % token # We want to keep checking for updates. So this must be a never ending loop while True: # My chat is up and running, I need to maintain it! Get me all chat updates get_updates = json.loads(requests.get(url + 'getUpdates').content) # Ok, I've got 'em. Let iterate through each one for update in get_updates['result']: # First make sure I haven't read this update yet if last_update < update['update_id']: last_update = update['update_id'] # I've got a new update. Let see what it is. if 'message' in update: # It a message! Let send it back :D requests.get(url + 'sendMessage', params=dict(chat_id=update['message']['chat']['id'], text=update['message']['text'])) # Let wait a few seconds for new updates sleep(3) 

A source

The bot I'm working on

+4
source share

This is really interesting, but you will definitely need a server to parse the JSON value and get chat_id from it.

+1
source share

All Articles