telebot/examples/awslambdaechobot/main.go

31 lines
581 B
Go
Raw Normal View History

2020-05-01 14:56:51 +00:00
package main
import (
"encoding/json"
"os"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
tb "gopkg.in/tucnak/telebot.v2"
)
func main() {
2020-07-25 21:01:39 +00:00
b, err := tele.NewBot(tele.Settings{
2020-05-01 14:56:51 +00:00
Token: os.Getenv("TELEBOT_SECRET"),
Synchronous: true,
})
if err != nil {
panic(err)
}
2020-07-25 21:01:39 +00:00
b.Handle(tele.OnText, func(m *tele.Message) { b.Send(m.Chat, m.Text) })
2020-05-01 14:56:51 +00:00
lambda.Start(func(req events.APIGatewayProxyRequest) (err error) {
2020-07-25 21:01:39 +00:00
var u tele.Update
2020-05-01 14:56:51 +00:00
if err = json.Unmarshal([]byte(req.Body), &u); err == nil {
b.ProcessUpdate(u)
}
return
})
}