Skip to content

Example repository for Telegraf.js + Serverless framework + AWS Lambda (Node.js Typescript)

Notifications You must be signed in to change notification settings

ozero/telegraf_sls_ts_example

Repository files navigation

Telegram bot for AWS Lambda (TS)

Example repository for Telegraf.js + Serverless framework + AWS Lambda (Node.js Typescript)

Setup

Env

  1. Clone this repo, path will be /path/to/project/telegraf_sls_ts_example
  2. Set up AWS CLI. Serverless fw uses its credentials.
  3. Set up AWS SDK layer for Lambda funtion in /path/to/project/aws-sdk-layer/nodejs
  4. Install Node.js v16.x from nodesource.
  5. Install Serverless Framework With $ npm install -g serverless
  6. Install required npm packages with $ yarn install

Telegram Bot token

  1. Open Telegram app & Create your new bot with @BotFather, then get a bot token.
  2. $ cp .env.dev.sample.json .env.dev.json
  3. paste your BOT TOKEN into .env.dev.json

Code

  1. Deploy into AWS Lambda with $ yarn sls deploy
  2. 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.
  3. 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> )
  4. Open Telegram app & /start with your bot.
  5. Let's code your function in src/functions/webhook/handler.ts then $ yarn sls deploy dev -f webhook

About

Example repository for Telegraf.js + Serverless framework + AWS Lambda (Node.js Typescript)

Topics

Resources

Stars

Watchers

Forks