Telegram Bot 2: OCR

Python + AWS Lambda + AWS API Gateway

Previous Article:
Telegram Bot 1: Stock Tracking

0. Demo

  1. Setup

- create AWS account

- talk to BotFather in telegram and create a bot. You will receive an authorization token.
- download the script and fill in the token in

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

- select “python” folder and add to archive (e.g.

*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:

- 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.

- upload the .zip file to lambda

5. Create an API Gateway

6. Set Webhook

- place the following URL in the browser and hit enter

- you should receive the following response:

- to view the Webhook information:




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store