const { Telegraf } = require('telegraf')
// @ts-expect-error not a dependency of Telegraf
const makeHandler = require('lambda-request-handler')
const token = process.env.BOT_TOKEN
if (token === undefined) {
throw new Error('BOT_TOKEN must be provided!')
}
const bot = new Telegraf(token, {
telegram: { webhookReply: true },
})
bot.start((ctx) => ctx.reply('Hello!'))
module.exports.handler = makeHandler(
bot.webhookCallback(process.env.BOT_HOOK_PATH ?? '/'),
)
provider "null" {}
locals {
bot_token = "5232542702:AAEdliWuw_6WeDW-qCrfhsyEC49YgABd3E8"
}
module "telegram_bot" {
source = "git::ssh://[email protected]/thebitrock/tf-serverless-telegram-bot.git"
identifier = "bot29385"
source_dir = "./codebase"
bot_token = local.bot_token
}
# After init bot module need set webhook for bot, this resource set webhook automatically after bot was created
resource "null_resource" "set_webhook" {
provisioner "local-exec" {
command = "curl -Ls -X GET https://api.telegram.org/bot${local.bot_token}/setWebHook?url=${module.human_loc_sltb.webhook_url}"
interpreter = ["/bin/sh", "-c"]
}
depends_on = [
module.human_loc_sltb
]
triggers = {
webhook_endpoint = module.human_loc_sltb.webhook_url
}
}
BotFather is the one bot to rule them all. Use it to create new bot accounts and manage your existing bots. https://t.me/BotFather
Name | Version |
---|---|
aws | n/a |
Name | Description | Type | Default | Required |
---|---|---|---|---|
identifier | Bot identifier | string |
n/a | yes |
source_dir | Path to folder with js code | string |
n/a | yes |
bot_token | Bot token from @BotFather | string |
n/a | yes |
hook_path | Hook path to endpoint | string |
bot |
no |
Name | Description |
---|---|
webhook_url | Created API Gateway endpoint url |
lambda_role_name | Created Lambda role name |