telebot/examples/awslambdaechobot
2020-07-26 00:08:03 +03:00
..
deploy.sh examples: add awslambdaechobot 2020-05-01 18:38:54 +00:00
go.mod mod: tidy 2020-06-13 13:48:22 +03:00
go.sum mod: tidy 2020-06-13 13:48:22 +03:00
init.sh examples: add awslambdaechobot 2020-05-01 18:38:54 +00:00
main.go telebot: tele is our new alias 2020-07-26 00:08:03 +03:00
main.tf examples: add awslambdaechobot 2020-05-01 18:38:54 +00:00
README.md telebot: tele is our new alias 2020-07-26 00:08:03 +03:00

This example shows how to write an echo telebot for AWS Lambda and how to launch it using Terraform.

This bot is different from a typical bot in two ways:

  1. It is configured with Settings.Synchronous = true. This disables asynchronous handlers to let Lambda wait for their completion:

    b, _ := tele.NewBot(tele.Settings{Token: token, Synchronous: true})
    
  2. Instead of Settings.Poller and bot.Start it calls bot.ProcessUpdate inside lambda.Start:

    lambda.Start(func(req events.APIGatewayProxyRequest) (err error) {
        var u tele.Update
        if err = json.Unmarshal([]byte(req.Body), &u); err == nil {
            b.ProcessUpdate(u)
        }
        return
    })
    

To launch the bot install Terraform, run ./init.sh and then ./deploy.sh. To tear down the cloud infrastructure run terraform destroy.