Closed plandem closed 1 year ago
Telegram Bot can work with https://core.telegram.org/bots/api#setwebhook If your labmda can wake up by webhook, you can use this approach, i think
I make function bot.ProcessUpdate
public. You can use this func for manually process updates.
Example lambda for Yandex.Cloud Functions
package main
import (
"context"
"encoding/json"
"net/http"
"os"
"github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
)
func Handler(rw http.ResponseWriter, req *http.Request) {
b, err := bot.New(os.Getenv("EXAMPLE_TELEGRAM_BOT_TOKEN"), bot.WithDefaultHandler(defaultHandler))
if err != nil {
rw.WriteHeader(http.StatusBadRequest)
return
}
update := models.Update{}
errDecode := json.NewDecoder(req.Body).Decode(&update)
if errDecode != nil {
rw.WriteHeader(http.StatusBadRequest)
return
}
b.ProcessUpdate(context.Background(), &update)
}
func defaultHandler(ctx context.Context, b *bot.Bot, update *models.Update) {
b.SendMessage(ctx, &bot.SendMessageParams{
ChatID: update.Message.Chat.ID,
Text: "You wrote: " + update.Message.Text,
})
}
cool! will try soon. Worried a bit about all these signal
and other OS stuff in serverless environment
e.g. lambda functions or anything else