Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best practics to use express with telegram-node-bot #170

Open
numkms opened this issue Feb 18, 2017 · 6 comments
Open

Best practics to use express with telegram-node-bot #170

numkms opened this issue Feb 18, 2017 · 6 comments

Comments

@numkms
Copy link

numkms commented Feb 18, 2017

Hello! Im try to use this framework with express framework for notice users via get query from php-app.
Well heres my code:
`'use strict'
const express = require('express');
const app = express();
app.listen(8008);

const Telegram = require('telegram-node-bot');
const TelegramBaseController = Telegram.TelegramBaseController;
const TextCommand = Telegram.TextCommand;
const tg = new Telegram.Telegram('MYTOKEN');`

So i get binded port error cause express execute many times.
Some Log


Telegram Worker started at 1804 PID


[log]
Telegram Worker started at 6180 PID


[log]
Telegram Worker started at 5904 PID


[log]
Telegram Worker started at 5300 PID


events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: bind EADDRINUSE null:8008
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at cb (net.js:1324:16)
    at shared (cluster.js:619:5)
    at Worker.<anonymous> (cluster.js:592:9)
    at process.<anonymous> (cluster.js:765:8)
    at emitTwo (events.js:111:20)
    at process.emit (events.js:191:7)
    at process.nextTick (internal/child_process.js:744:12)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: bind EADDRINUSE null:8008
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at cb (net.js:1324:16)
    at shared (cluster.js:619:5)
    at Worker.<anonymous> (cluster.js:592:9)
    at process.<anonymous> (cluster.js:765:8)
    at emitTwo (events.js:111:20)
    at process.emit (events.js:191:7)
    at process.nextTick (internal/child_process.js:744:12)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)

What should i do for fix this issue?
Thx and sorry for bad english :)

@jesusgn90
Copy link

Set number of workers to 1 maybe works...

const tg = new Telegram.Telegram('YOUR_TOKEN', {
workers: 1
})

@salishivani
Copy link

how to give url link when clicking on button?

@muety
Copy link

muety commented May 22, 2017

I have the same problem. Are there any solution to this?

@azevedovadio
Copy link

I have the same problem. Did anyone get the solution?

@numkms
Copy link
Author

numkms commented May 28, 2017

Yes i have, u need to use express init in $.onMaster callback

@numkms
Copy link
Author

numkms commented May 29, 2017

`//init modules
const express = require('express');
const port = 8888;
var listener = express();

const Telegram = require('telegram-node-bot')
const TelegramBaseController = Telegram.TelegramBaseController
const TextCommand = Telegram.TextCommand

let tg = new Telegram.Telegram('key');

tg.onMaster(() => {
listener.listen(port, function (){
console.log('Your app runing on '+port);
});

        listener.get('/query',function(req,res){
                res.send('your response');
        });

});`
Like this

@numkms numkms closed this as completed May 29, 2017
@numkms numkms reopened this May 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants