mullwar / telebot

The easy way to write Telegram bots in Node.js
https://www.npmjs.com/package/telebot
MIT License
1.48k stars 270 forks source link

How i can deploy the Bot ? #193

Closed xMA3x closed 3 years ago

xMA3x commented 3 years ago

I have trayed is : 1- npm install -g vercel 2- vercel it deployed but the bot doesn't work and I need to run it manually

also trayed to deeply it in https://vercel.com/ after uploading it as a repo, but nothing works to

TeLoardBruh commented 3 years ago

Hello,

the issue is about the port,

try to use polling, so if your bot get disconnected, the polling option will bring back the bot to reconnect with new port. for example:

`const bot = new TeleBot({ token: process.env.bot_token, polling: { // Optional. Use polling. interval: 1000, // Optional. How often check updates (in ms). timeout: 0, // Optional. Update polling timeout (0 - short polling). // limit: 100, // Optional. Limits the number of updates to be retrieved. retryTimeout: 5000, // Optional. Reconnecting timeout (in ms). // proxy: 'http://username:password@yourproxy.com:8080' // Optional. An HTTP proxy to be used. },

}

);`

Hope this can help.

xMA3x commented 3 years ago

Hello,

the issue is about the port,

try to use polling, so if your bot get disconnected, the polling option will bring back the bot to reconnect with new port. for example:

`const bot = new TeleBot({ token: process.env.bot_token, polling: { // Optional. Use polling. interval: 1000, // Optional. How often check updates (in ms). timeout: 0, // Optional. Update polling timeout (0 - short polling). // limit: 100, // Optional. Limits the number of updates to be retrieved. retryTimeout: 5000, // Optional. Reconnecting timeout (in ms). // proxy: 'http://username:password@yourproxy.com:8080' // Optional. An HTTP proxy to be used. },

}

);`

Hope this can help.

unfortunately, it didn't work. this is the code that i used

const TeleBot = require('telebot');
const bot = new TeleBot({
    token: "xxx", // Required. Telegram Bot API token.
    polling: {},
});
bot.on('text', (msg) => msg.reply.text(msg.text));
bot.start();
and it did work when I run the node command in the terminal, but even after deploy it didn't work

I don't want that exact way to deoply (using vercel), if there is any other way it will be greatly helpful

TeLoardBruh commented 3 years ago

maybe you can try this one

const bot = new TeleBot({ token: process.env.bot_token, polling: { // Optional. Use polling. interval: 1000, // Optional. How often check updates (in ms). timeout: 0, // Optional. Update polling timeout (0 - short polling). // limit: 100, // Optional. Limits the number of updates to be retrieved. retryTimeout: 5000, // Optional. Reconnecting timeout (in ms). // proxy: 'http://username:password@yourproxy.com:8080' // Optional. An HTTP proxy to be used. allowedUpdates: [], },

}

);

xMA3x commented 3 years ago

maybe you can try this one

const bot = new TeleBot({ token: process.env.bot_token, polling: { // Optional. Use polling. interval: 1000, // Optional. How often check updates (in ms). timeout: 0, // Optional. Update polling timeout (0 - short polling). // limit: 100, // Optional. Limits the number of updates to be retrieved. retryTimeout: 5000, // Optional. Reconnecting timeout (in ms). // proxy: 'http://username:password@yourproxy.com:8080' // Optional. An HTTP proxy to be used. allowedUpdates: [], },

}

);

unfortunately, the same problem, i rly idk where the probelm is this is the scrpit

const TeleBot = require('telebot'); const bot = new TeleBot({ token: "xxx", polling: { // Optional. Use polling. interval: 1000, // Optional. How often check updates (in ms). timeout: 0, // Optional. Update polling timeout (0 - short polling). // limit: 100, // Optional. Limits the number of updates to be retrieved. retryTimeout: 5000, // Optional. Reconnecting timeout (in ms). // proxy: 'http://username:password@yourproxy.com:8080' // Optional. An HTTP proxy to be used. allowedUpdates: [], }, }); bot.on('text', (msg) => msg.reply.text(msg.text)); bot.start();

and this is the package

{ "name": "telgrambot", "version": "1.0.0", "description": "", "main": "index.js", "dependencies": { "next": "^10.0.9", "react": "^17.0.2", "telebot": "^1.4.1", "vercel": "^21.3.3" }, "devDependencies": {}, "scripts": { "test": "node index.js", "start": "node index.js" }, "keywords": [], "author": "", "license": "ISC" }

where is index.js is the name of the code file, and this is the log of vervel

`

14:01:05.765 Retrieving list of deployment files...
14:01:07.302 Downloading 3 deployment files...
14:01:07.365 Analyzing source code...
14:01:09.189 Uploading build outputs...
14:01:09.283 Deploying build outputs...
14:01:10.959 Done with static build

`

TeLoardBruh commented 3 years ago

i deployed on Heroku and it worked, for me using that script.

Why don't you try heroku

TeLoardBruh commented 3 years ago

again the problem is with the port of your bot hosting, you need to use proccess.env.PORT in somewhere on your vervel

xMA3x commented 3 years ago

i deployed on Heroku and it worked, for me using that script.

Why don't you try Heroku

I had searched for the Heroku method, but everything is for node telegram bot api not for telebot i had found that repo and it worked for node telegram bot, but for telebot it didn't

if you know any way to use Heroku for telebot it will be graldy appreciated

TeLoardBruh commented 3 years ago

So basically it’s like deploy normal node js app to heroku. 1 . u need to to connect your repo with heroku

  1. create Procfile
  2. set up in package.json for start commend, this one is to tell heroku where to run your app, for example “start” : “node app.js”
  3. set your bot script like the one i sent you
  4. push your code to the server

if you still not sure i can help you restructure your file for pushing to heroku

xMA3x commented 3 years ago

So basically it’s like deploy normal node js app to heroku. 1 . u need to to connect your repo with heroku

  1. create Procfile
  2. set up in package.json for start commend, this one is to tell heroku where to run your app, for example “start” : “node app.js”
  3. set your bot script like the one i sent you
  4. push your code to the server

if you still not sure i can help you restructure your file for pushing to heroku

yes please I want some help, I just watched those 2 videos https://www.youtube.com/watch?v=IuUY-OJ0GXE&t=941s https://www.youtube.com/watch?v=-yWuLRJhoNI&t=530s

did all the steps and changed what need to be changed and the same problem, no response

TeLoardBruh commented 3 years ago

can you open heroku , go to see in logs what’s the error can you screenshot here

TeLoardBruh commented 3 years ago

did you include your bot token in heroku config ?

xMA3x commented 3 years ago

here is the build log

-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/nodejs
-----> Node.js app detected

-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true

-----> Installing binaries
       engines.node (package.json):  unspecified
       engines.npm (package.json):   unspecified (use default)

       Resolving node version 14.x...
       Downloading and installing node 14.16.0...
       Using default npm version: 6.14.11

-----> Restoring cache
       - node_modules

-----> Installing dependencies
       Installing node modules
       added 48 packages in 1.533s

-----> Build

-----> Caching build
       - node_modules

-----> Pruning devDependencies
       audited 48 packages in 0.735s

       2 packages are looking for funding
         run `npm fund` for details

       found 0 vulnerabilities

-----> Build succeeded!
 !     This app may not specify any way to start a node process
       https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type
-----> Discovering process types
 ~     Mis-cased procfile detected; ignoring.
 ~     Rename it to Procfile to have it honored.
       Procfile declares types     -> (none)
       Default types for buildpack -> web
-----> Compressing...
       Done: 33.1M
-----> Launching...
       Released v7
       https://teegmrabotaap.herokuapp.com/ deployed to Heroku

here is the my repo https://github.com/xMA3x/telegrrambot

xMA3x commented 3 years ago

will, after locking in the log and the repo, it appears that the package didn't upload for an updated version when did that it worked, anyway thank you very much for standing with me all that time and fast replay <3

TeLoardBruh commented 3 years ago

ok nice also change the procfile into Procfile glad i can assist you

xMA3x commented 3 years ago

ok nice also change the procfile into Procfile glad i can assist you

Hello sir, i have another issue, can you help me on it ?

TeLoardBruh commented 3 years ago

ok nice also change the procfile into Procfile glad i can assist you

Hello sir, i have another issue, can you help me on it ? Yes sure man, how can i help you

xMA3x commented 3 years ago

ok nice also change the procfile into Procfile glad i can assist you

Hello sir, i have another issue, can you help me on it ? Yes sure man, how can i help you

i have already posted 3 issues, i wish you could look at them