Telegram
Instruction on how to start developing Telegram bot.
Local development
Video
Steps
- To start work with telegram you have to get telegram token
from @BotFather. Write to BotFather
/newbot
, write display name of your new bot, then username and you should get telegram token.
Then open
my-app
directory which you have install viacreate-urban-bot
and paste the telegram token to.env
file.telegram token in .env
After this open
src/index.ts
orsrc/index.js
and uncomment// import './render/telegram';
src/index
Your bot is ready to launch! Run
npm run dev
inmy-app
directory and write something to your bot. It should work as default app with two commands/echo
and/logo
.
If you see error looks like
error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: connect ECONNREFUSED 127.0.0.1:9150"}
probably an internet provider blocks Telegram connection. You need to use a VPN, or you could use the Tor browser, see the example.
Deploy
Heroku
Video
Steps
Register on heroku and install heroku cli and run
heroku login
in a terminal.Go to a new app and create a new.
Go to your local urban-bot app folder if you have already one. For a new app do the first three steps.
Paste heroku app url to
.env
file asWEBHOOK_HOST
. You could get it from "Open app" button.heroku open app button
Run
npx urban-bot set-webhook telegram
in a terminal from your local urban-bot app folder.Paste telegram token to "Config Vars" section as
TELEGRAM_TOKEN
in heroku app settings https://dashboard.heroku.com/apps/<YOUR_APP_NAME>/settings.heroku config vars
Run
git init
in your local urban-bot app folder if you did not.Add git remote by run
heroku git:remote -a <YOUR_APP_NAME>
.Deploy.
git add .
git commit -am "make it better"
git push heroku master -u
- Check your bot!