Last active
April 6, 2020 04:50
-
-
Save wwwmarcos/c705bcf5add42ef86c69fd45f42695f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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