Blog for Learning

| lesson material | material summary | questions and answers | definitions | types and examples | other information | materi pelajaran | ringkasan materi | pertanyaan dan jawaban | definisi | jenis-jenis dan contoh-contoh | informasi lainnya |

Powered by Blogger.


How to Make a Telegram Bot with Service

Tutorial on Creating a Telegram Bot
Telegram bots can be made with various programming languages:
Can PHP , Javascript , Java , Python , Ruby , and so on.
There are two basic knowledge that must be understood:
  1. How to Make an HTTP Request and Webhook.
  2. How to Parse JSON from a Webservice.
But, now the problem is where do we put the codes?
"Rent a server ..."
The flakes are too expensive, if only for learning.
"What if you use it for free."
yep, that's the answer.
One of the services hosting free supply WebHook is .
In this paper, we will learn how to make Telegram Bots using the Webhookmethod using the service .
So that later we will be able to make a bot that is ready to use.
Bot Relations with
There are two main discussions in this guide:
  1. How to Create Bots in BotFather
  2. How to Make Services for Machine Bot on uses javascript programming language.
Let's start…

Materials needed:

  1. Telegram Bot Token - key to accessing bots.
  2. account - please register first !

Make APIs and Tokens

Please open @botfather to create a new bot.
On the command bot ( /) button, select /newBot.
Register for a new bot
After that, please reply with the bot name. Example: "Mr. Farmer".
Give the name of the bot
Next, we will be asked to provide a username for the bot.
Each username bot must end with the word "bot" behind it.
Create a username for the bot
after that, we will get the bot bot token code.
Get the Bot token
Save the token, because we will use it to connect it to

Make a Service at

After you create an account at, please create a new service.
Click here to make it.
Fill in the name of the hook to be made, for example "farmer".
Make a webhook for bots
Click Create to make it.

Creating Environment Variables (ENV)

ENVWe will use the environment variable ( ) to store the bot token so that we don't type the token in the code. Because tokens are confidential.
Please go to to create environment variables.
Create environment variables

Creating a Code for Bot Control

Treat the Hook Source code :
Default webhook code
Please change the code (Hook Source) with this code.
module['exports'] = function petaniBot(hook) {

    // impor modul request
    var request = require('request');

    // buat atau kirim request ke bot telegram'' + hook.env.token_petani_bot + '/sendMessage')
              'text': 'Anda mengirim: ' + hook.params.message.text
The function of the code above will only send a request to the Telegram Bot, if there is a request or chat entered.
The contents of the submission are JSON: (see Bot API documentation )
     "text": "Anda mengirim: " + hook.params.message.text
In order to be sent, we need a bot token.
The bot token is already in a variable token_petani_bot, so it's only usable:'' + hook.env.token_petani_bot + '/sendMessage').form(<data>);
The control code is ready ...
Next, we will connect with the bot.

How to Connect a Telegram Bot with

Bot Relations with
To connect a bot to a hook, please arrange the URL to be like this:<TOKEN>/setWebhook?url=<hook-user>/<hook-name>
Please replace:
  • <TOKEN> with your bot token
  • <hook-user> with your username
  • <hook-name> with the name of the service / service hook that you made
After that, please open the URL via the browser.
If you get a reply like this, then the bot is successfully connected with the hook service.
Linking Bots with Webhook


Please open or chat with the bot that was created, .
Bot Test

Conclusions and recommendations

We can control the Telegram bot with the code stored in
We can determine how bot behavior through code.
In the example above, the bot has successfully received and sent replies.
Suggestions for further development:
Thank you for following this guide ...
Don't forget to join the @partanikode channel on the Telegram to get the latest information.
0 Komentar untuk "How to Make a Telegram Bot with Service"

Silahkan berkomentar sesuai artikel

Template By Kunci Dunia
Back To Top