Telegram Bot 2: OCR
Python + AWS Lambda + AWS API Gateway
Previous Article:
Telegram Bot 1: Stock Tracking
0. Demo
- Setup
– create AWS account
– talk to BotFather in telegram and create a bot. You will receive an authorization token. https://core.telegram.org/bots
– download the script and fill in the token in lambda_function.py
https://github.com/simonlaw101/tg_bot
token = 'YOUR_TOKEN'
2. Create a Lambda function
– set a longer timeout (Optional)
3. Add a Layer for external library dependencies (Optional)
– create a new folder named “python” & install the required external library inside
pip3 install --target . YOUR_LIBRARY
– select “python” folder and add to archive (e.g. layer.zip)
*Note that the library must be in the following structure (inside python folder), otherwise you will get import module error during runtime
AWS official example file structure for the Pillow library:
pillow.zip
│ python/PIL
└ python/Pillow-5.3.0.dist-info
– go to your function
– layer is immutable
– upload new version for any changes
4. Deploy code to Lambda
– create a folder including all your source code files
– select all files and add to archive (e.g. lambda_function.zip)
– upload the .zip file to lambda
5. Create an API Gateway
6. Set Webhook
– place the following URL in the browser and hit enter
https://api.telegram.org/bot<YOUR_TOKEN>/setWebHook?url=<INVOKE_URL>
– you should receive the following response:
{"ok":true,"result":true,"description":"Webhook was set"}
– to view the Webhook information:
https://api.telegram.org/bot<YOUR_TOKEN>/getWebhookInforesponse:
{"ok":true,"result":{"url":"https://9XXXXXXXXh.execute-api.us-east-2.amazonaws.com/v1","has_custom_certificate":false,"pending_update_count":0,"max_connections":40,"ip_address":"10.10.10.10"}}
Reference:
Telegram Bot API
The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram.To learn how to create…
Ten articles before and after
telegram登录收不到短信验证码 | – Telegram 简体版
Telegram 中国手机号收不到短信怎么办?(2022 更新) | – Telegram 简体版
Telegram迎来Payments 2.0支付服务、语音群聊预约功能和Web新版本 | – Telegram 简体版telegram中文网页版
Build an e-commerce telegram web app bot? – Telegram 简体版Telegram中文官网下载
19:27 Time | Conversion and Information | – Telegram 繁体版 下载
7 Builders For No-Code Creation of Chatbots in Telegram – Telegram 简体版
Cryptocurrency payment gateway for telegram bots and websites – Telegram 简体版
Telegram Reminder Bot. Telegram along with messaging feature… – Telegram 简体版