Node-telegram-bot-api: Deploy Heroku

Created on 24 Aug 2015  路  11Comments  路  Source: yagop/node-telegram-bot-api

Hi,

How can I deploy my local project to heroku?

I'm trying with Procfile: "worker: node index.js" and after 60 seconds console shows:

Process exited with status 137
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

help wanted

Most helpful comment

I have a working bot deployed on Heroku. Here is what I did:

  • use the port provided by Heroku and listen on '0.0.0.0' (probably process.env.HOST is better)
  • use the external URL (https://my-app.herokuapp.com:443/) for the webhook
  • use a path like /bot for the webhook (see https://github.com/yagop/node-telegram-bot-api/blob/master/examples/httpsWebHook.js)

In your case, I would change the code like this:

var TelegramBot = require('node-telegram-bot-api'),
    port = process.env.PORT || 443,
    host = '0.0.0.0',  // probably this change is not required
    externalUrl = process.env.CUSTOM_ENV_VARIABLE || 'https://my-app.herokuapp.com',
    token = process.env.TOKEN,
    bot = new TelegramBot(process.env.TOKEN, { webHook: { port : port, host : host } });
bot.setWebHook(externalUrl + ':443/bot' + token);

This is my bot, if you want to check all the code: https://github.com/davidepedranz/coudrino-bot (my bot does not set a webhook if it does not find the URL in the WEBHOOK_URL env variable).

All 11 comments

As example:

// This is needed if the app is run on heroku:

var port = process.env.PORT || 8080;

var io = require('socket.io').listen(app.listen(port));

There is nothing with Socket.io on this proyect but you can take the port through environment variables.

var port = process.env.PORT || 8443;
var host = process.env.HOST;
var bot = new TelegramBot(token, {webHook: {port: port, host: host}});

Sorry, i mean define PORT and HOST

I have a similar problem.

this is my config

var TelegramBot = require('node-telegram-bot-api'),
    port = process.env.PORT || 443,
    host = process.env.HOST,
    bot = new TelegramBot(process.env.TOKEN, { webHook : { port : port, host : host } });
bot.setWebHook(/* here should go the url, right? */);

I tried to bind the url that Heroku gave me to a environment variable (like the TOKEN) but it's still not working, both locally and remotely.

I don't know what am I doing anymore, I feel like I'm banging rocks together at this point.

I have a working bot deployed on Heroku. Here is what I did:

  • use the port provided by Heroku and listen on '0.0.0.0' (probably process.env.HOST is better)
  • use the external URL (https://my-app.herokuapp.com:443/) for the webhook
  • use a path like /bot for the webhook (see https://github.com/yagop/node-telegram-bot-api/blob/master/examples/httpsWebHook.js)

In your case, I would change the code like this:

var TelegramBot = require('node-telegram-bot-api'),
    port = process.env.PORT || 443,
    host = '0.0.0.0',  // probably this change is not required
    externalUrl = process.env.CUSTOM_ENV_VARIABLE || 'https://my-app.herokuapp.com',
    token = process.env.TOKEN,
    bot = new TelegramBot(process.env.TOKEN, { webHook: { port : port, host : host } });
bot.setWebHook(externalUrl + ':443/bot' + token);

This is my bot, if you want to check all the code: https://github.com/davidepedranz/coudrino-bot (my bot does not set a webhook if it does not find the URL in the WEBHOOK_URL env variable).

@davidepedranz shouldn't you provide also a certificate somehow?

If I understand the Telegram Bot's APIs right, you can decide to supply a certificate if you want Telegram to use it to verify the SSL connection to your server.

In this case, I do not provide any certificate because Telegram trusts Heroku's certificate, so a custom certificate is not required. I think the provided this option to allow developers to use self-signed certificates running on any host. ;-)

@davidepedranz Thanks for clarification

@davidepedranz If I'm providing a certificate is HTTPS still required?

@roccomuso Yes, Telegram wants still HTTPS, but you can provide your self-signed certificate at the bot startup to make it run an HTTPS server (see https://core.telegram.org/bots/api#setwebhook)

I have the same error:

const { chatID, authToken, url, PORT, delay } = process.env;

const options = {
  webhook: {
    port: PORT || 443,
    host: '0.0.0.0'
  },
};

const bot = new TelegramBot(authToken, options);

bot.setWebHook(`${url}:443/bot${authToken}`);
setInterval(() => bot.sendMessage(chatID, 'I am alive on Heroku'), delay);

What I doing wrong?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

saeedhei picture saeedhei  路  4Comments

Lemmmy picture Lemmmy  路  3Comments

Kasra-S picture Kasra-S  路  3Comments

mbrammer picture mbrammer  路  3Comments

Panthro picture Panthro  路  3Comments