- Google Cloud Platform with Billing enabled.
- Bot created using the @BotFather on Telegram.
- Bot Token issued by the @BotFather.
1) Go to Google Cloud Console.
- Name: webhook
- Trigger: HTTP
- Runtime: Python 3.7
- URL: Copy this URL, you will use it later
import telegram
bot = telegram.Bot('<REPLACE WITH BOT TOKEN>')
def webhook(request):
if request.method == "POST":
update = telegram.Update.de_json(request.get_json(force=True), bot)
chat_id = update.message.chat.id
bot.sendMessage(chat_id=chat_id, text=update.message.text)
return True
python-telegram-bot
https://api.telegram.org/bot<REPLACE WITH BOT TOKEN>/setWebhook?url=<REPLACE WITH FUNCTION URL>
If you did it correctly you should get the following:
{"ok":true,"result":true,"description":"Webhook was set"}
Alternatively you can use the gcloud command. Assuming you have src/main.py and src/requirements.txt, gcloud authenticated and with a Project ID set, you'd simply:
$ cd src
$ gcloud functions deploy webhook2 --runtime python37 --trigger-http