question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Heroku deployment

See original GitHub issue

After deployment to Heroku the bot receives all messages, but doesn’t answer. In case the bot sends two messages consequently in a short period of time, only the second one gets delivered. When polling is used, all the messages sent by the bot get delivered. I also tried using webhooks without express, but nothing changed. I found several related issues, but in all of them the author ended up using node-telegram-bot library which solved the problem.

The code used for setting webhook:

const express = require("express");
const expressApp = express();

const bot = new Telegraf(process.env.BOT_TOKEN);
bot.telegram.setWebhook(`${process.env.BOT_URL}/bot${process.env.BOT_TOKEN}`);
expressApp.use(bot.webhookCallback(`/bot${process.env.BOT_TOKEN}`));

bot.use(Telegraf.log());
bot.use(session({
    ttl: 100
}));

expressApp.get("/", (req, res) => {
    res.send("Hello World!");
});
expressApp.listen(process.env.PORT, () => {
    console.log(`Example app listening on port ${process.env.PORT}!`);
});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
coxatocommented, Feb 9, 2021

Results in `Error listen EADDRINUSE.

Port is used by another application.

index.express.js

const Telegraf = require('telegraf')
const express = require('express')
const expressApp = express()

const port = process.env.PORT || 5000 // Correct port will be returned here
const bot = new Telegraf(process.env.BOT_TOKEN)

expressApp.use(bot.webhookCallback('/secret-path'))
bot.telegram.setWebhook('https://MY-APP.heroku.com/secret-path')

expressApp.get('/', (req, res) => {
  res.send('Hello World!')
})

expressApp.listen(port, () => {
  console.log(`Example app listening on port ${port}!`)
})

NOTE (Server): .launch will create a new server. NOTE (Security): Do not use token in secret path.

Hi, I have a question, what is /secret-path ?, What am I supposed to put there?

1reaction
TorlanDeltacommented, May 25, 2019

@TiagoDanin This is not what I asked, although I do appreciate your effort.

What I do struggle with is how to implement bot.launch in the code you provided yourself.

I have exactly the same setup with expessApp and stuff, so I was having trouble modifying my code to fit the bot.launch in.

Also I updated the telegraf obviously and I am still experiencing random malfunctioning API calls.

What is skipped almost always is the calls of ctx.telegram.deleteMessage() and ctx.answerCbQuery().

ctx.telegram.editMessageMedia() seems to ALWAYS work though.

I can post the whole code base of mine, but since its multiple files I do feel like it’s too much to go through for you guys. The fact is that it’s all working fine with locally hosted long polling app.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deployment - Heroku Dev Center
Most Heroku deployments are performed with Git. Heroku also supports Docker-based deployments. Additionally, you can deploy to Heroku via any of the following ......
Read more >
Heroku Deploy – How to Push a Web App or Site to Production
Heroku allows developers to quickly and almost painlessly deploy an application on a web server. It also provides a lot of plugins that...
Read more >
Heroku Deployment Methods: 1/3 - YouTube
This Heroku Showcase demonstrates several deployment methods available on the Heroku Platform. In this, the first of three deployment ...
Read more >
How To Deploy to Heroku in 5 Minutes - YouTube
In this video I teach how to deploy an api to Heroku in under 5 minutes. Heroku is one of the best services...
Read more >
Heroku Deployment Guide | The Full-Stack Blog - GitHub Pages
Deploy to Heroku ... Okay, it's time to actually deploy your application! Deployment allows other developers to give you more detailed feedback ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found