Skip to content

Instantly share code, notes, and snippets.

@wwwmarcos
Last active April 6, 2020 04:50
Show Gist options
  • Save wwwmarcos/c705bcf5add42ef86c69fd45f42695f9 to your computer and use it in GitHub Desktop.
Save wwwmarcos/c705bcf5add42ef86c69fd45f42695f9 to your computer and use it in GitHub Desktop.
// index.js
const express = require('express')
const Telegraf = require('telegraf')
const app = express()
const APP_PORT = 3000
const { BOT_TOKEN } = process.env
const CURRENT_HOST = ''
// instanciando o bot
const bot = new Telegraf(BOT_TOKEN, {
telegram: {
webhookReply: false
}
})
// configuração de ação tosca no bot
bot.on('text', ctx => {
return ctx.reply(`msg recebida de: ${ctx.message.from.username}`)
})
// união entre bot e express
app.use(bot.webhookCallback('/callback'))
app.get('/setup', async (_req, res) => {
const url = `${CURRENT_HOST}/callback`
await bot.telegram.setWebhook(url)
res.send(`listening on ${CURRENT_HOST}`)
})
app.listen(APP_PORT, () => {
console.log(`listening on ${APP_PORT}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment