Webhook working with one bot but not another.
See original GitHub issueContext
I can run a barebones bot using my webhook and all works perfectly fine:
index.js
const Telegraf = require('telegraf')
const express = require('express')
const expressApp = express()
const bot = new Telegraf('KEY HERE')
if(process.env.NODE_ENV !== 'production') {
bot.telegramdeleteWebhook()
bot.startPolling()
} else {
expressApp.use(bot.webhookCallback('/CM'))
bot.telegram.deleteWebhook()
bot.telegram.setWebhook('https://bots.xxxx.com/CM')
}
bot.start((ctx) => ctx.reply('Welcome'))
bot.help((ctx) => ctx.reply('Send me a sticker'))
bot.on('sticker', (ctx) => ctx.reply(' ^ ^ ^ '))
bot.hears('hi', (ctx) => ctx.reply('Hey there'))
bot.hears(/buy/i, (ctx) => ctx.reply('Buy-buy'))
expressApp.get('/', (req, res) => {
res.send('Hello World!')
})
expressApp.listen(8071, () => {
console.log('Example app listening on port 8071!')
})
bot.catch((err) => {
console.log('Ooops', err)
})
As you can see I have an IF statement to select whether running in production or not.
When trying to implement the same methods in my actual bot project, I see the logger receiving the messages from the telegram user, but the replies are not being processed. It’s as if the bot can see the inbound message but does not do anything after this.
My file structure is:
Paste 1: App/Bot/index.js
const Telegraf = require('telegraf');
const API_KEY = require('../../Config').envs[process.env.NODE_ENV].telegramBot.API_TOKEN;
const user = require('./Middleware/storeUser');
const filters = require('./Middleware/Filters');
const log = require('../../Utilities/Logger');
const express = require('express');
// Middleware dependencies
const TelegrafLogger = require('telegraf-logger');
const commandParts = require('telegraf-command-parts');
// Initialise classes
const telegramBot = new Telegraf(API_KEY);
const telegramBotLogger = new TelegrafLogger();
// Set username
telegramBot.telegram.getMe().then((botInfo) => {
telegramBot.options.username = botInfo.username;
});
// Initialise Middleware
telegramBot.use(telegramBotLogger);
telegramBot.use(user());
telegramBot.use(filters());
telegramBot.use(commandParts());
telegramBot.catch((err) => {
log.error(err);
});
// Webhook setup
const expressApp = express();
expressApp.get('/', (req, res) => {
res.send('Hello World!');
});
expressApp.listen(8071, () => {
log.debug('Example app listening!');
});
if (process.env.NODE_ENV === 'production') {
expressApp.use(telegramBot.webhookCallback('/CM'));
telegramBot.telegram.setWebhook('https://bots.xxxxxxx.com/CM');
}
module.exports = telegramBot;
Paste 2: App/index.js - The main program starts here.
const log = require('../Utilities/Logger');
const botClient = require('./Bot');
const Helpers = require('./Bot/Helpers');
function startApp() {
log.info(`Starting environment: ${process.env.NODE_ENV}`);
if (process.env.NODE_ENV !== 'production') {
// Start polling as we are not in production
botClient.telegram.deleteWebhook();
botClient.startPolling();
}
// Load plugin modules
Helpers.loadPlugins();
return log.info('App loaded.');
}
startApp();
An example of the logs:
[2018-05-16T04:43:05.067] [INFO] default - Starting environment: production - [ ../../App/index.js:6:7]
[2018-05-16T04:43:05.085] [INFO] default - App loaded. - [../../App/index.js:12 :14]
message => @munsd Chris (3434234324): <text> /start
message => @munsd Chris (3434234324): <text> /test
message => @munsd Chris (3434234324): <text> hi
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Triggering a bot with a webhook from another system (Thinkific)
I have a learning management system (LMS) that has a webhook that sends a POST to a URL with a JSON payload. I'd...
Read more >Unable to send a webhook only in one server - Stack Overflow
Webhooks are enabled in the intents and the text channel. This exception is only being raised in one server, it works fine in...
Read more >Make a bot for simple interactions in Teams using a Webhook
The solution is a Webhook in Teams and a Bot (surprised?). This works as ... It will not work with branching dialogs, or...
Read more >Messages not reaching my bot - Cisco Community
This sounds like an issue with your webhook. I presume you have a messages:created webhook, was this created with the bot token?
Read more >How To Create a Bot That Sends Multiple Webhook ...
How To Create a Bot That Sends Multiple Webhook Responses Via One Trigger · This tutorial still requires an admin to trigger the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Maybe the problem is, that one of the middlewares doesn’t return
next()
? For example, this works:while this doesn’t:
So I would suggest to look if (1) every middleware get’s called and (2) they all return next()
Ignore - my bad on this one. Lots of return statements missing on functions 👍