Telegram Bot using AWS API Gateway and AWS Lambda using awesome serverless package.
- Go to Telegram Web.
- Start a chat with @BotFather.
- Type
/start
. - Type
/newbot
to create a new bot. - After you created the bot, you get HTTP API access token.
- Create AWS account here
- Get AWS credentials (read more how get it).
- Export credentials to
~/.bash_profile
or terminal:
export AWS_ACCESS_KEY_ID=<ACCESS_KEY_ID>
export AWS_SECRET_ACCESS_KEY=<SECRET_ACCESS_KEY>
or add these variables to ~/.aws/credentials
(I recommend this way):
[default]
aws_access_key_id = <ACCESS_KEY_ID>
aws_secret_access_key = <SECRET_ACCESS_KEY>
- Create
.env
file and add telegram access token. Also you can add telegram proxy url (optional):
TELEGRAM_TOKEN=<TELEGRAM_ACCESS_TOKEN>
TELEGRAM_PROXY=
- Deploy lambda:
npm run deploy
You get endpoints, like that
endpoints:
POST - https://dfc5ofqqm0.execute-api.us-east-2.amazonaws.com/dev/
- Replace <TELEGRAM_ACCESS_TOKEN> with your Telegram HTTP API access token obtained in the first step.
- Replace <INVOKE_URL> with your endpoint url which you get in the previous step.
Run this command:
$ curl --data "url=<INVOKE_URL>" "https://api.telegram.org/bot<TELEGRAM_ACCESS_TOKEN>/setWebhook"
You should get back a response similar to this:
$ {"ok":true,"result":true,"description":"Webhook was set"}
- Send message to your Telegram Bot that you have created.
- Type any message.
- You should get your message back.