Example repository for Telegraf.js + Serverless framework(v3) + AWS Lambda (Node.js Typescript)
- Clone this repo, path will be
/path/to/project/telegraf_sls_ts_example
- Set up AWS CLI. Serverless fw uses its credentials.
- Set up AWS SDK layer for Lambda funtion in
/path/to/project/aws-sdk-layer/nodejs
- Install Node.js v16.x from nodesource.
- Install Serverless Framework With
$ npm install -g serverless
- Install required npm packages with
$ yarn install
- Open Telegram app & Create your new bot with
@BotFather
, then get a bot token. $ cp .env.dev.sample.json .env.dev.json
- paste your
BOT TOKEN
into.env.dev.json
- Deploy into AWS Lambda with
$ yarn sls deploy
- Make sure these items:
- Your Lambda function exists on AWS, specified region.
- BOT_TOKEN was written in function's Environment variables.
- Make sure your
API ENDPOINT URL
on deploy log, that executes your Lambda function.
- Set webhook with Telegram API. Open
https://api.telegram.org/bot<BOT_TOKEN>/setWebHook?url=<API_ENDPOINT_URL>
in browser.- ( API_ENDPOINT_URL looks like:
https://abcdefghijk.execute-api.<REGION-NAME>.amazonaws.com/<STAGE>/<RESOURCE>
)
- ( API_ENDPOINT_URL looks like:
- Open Telegram app &
/start
with your bot. - Let's code your function in
src/functions/webhook/handler.ts
then$ yarn sls deploy dev -f webhook