AUTOMATED BOTS
Bots are really interesting and easy to make, you just have to learn how it is being made just simply using multiple concepts, here in this article i will tell you a little about how to make a bot using an open source messaging application "Telegram".
Follow just a couple of simple steps and learn how to use python to create an interesting automated bots for usage.
You need couple of things to create a bot;
1) Telegram Application.
2) A little Knowledge of Python Programming.
You can write a Telegram chat bot in any language you want. Some of the main options apart from Python would be Java, PHP, or Ruby. If you are more familiar with a different high-level programming language, then you might prefer to use that instead, but here i am using Python, because it is easy to use and learn; As a matter of first importance, to make bot you need to have a Telegram account. Follow these steps;
Follow just a couple of simple steps and learn how to use python to create an interesting automated bots for usage.
You need couple of things to create a bot;
1) Telegram Application.
2) A little Knowledge of Python Programming.
You can write a Telegram chat bot in any language you want. Some of the main options apart from Python would be Java, PHP, or Ruby. If you are more familiar with a different high-level programming language, then you might prefer to use that instead, but here i am using Python, because it is easy to use and learn; As a matter of first importance, to make bot you need to have a Telegram account. Follow these steps;
- Add BotFather to your contact list.
- Begin a discussion with BotFather by clicking Start catch. You will see an order list quickly.
- Keeping in mind the end goal to make the bot, you need to type /newbot charge and take after the directions. Be watchful, your bot's username needs to end with bot. For instance, MathsBot or CryptoBot
- After selecting the username, you can access the token of your bot, from botfather,
- Select mybots from the options.
- Select your own bot, and after that click API TOKEN, and a long string will be generated that will be the token of your bot.
- We're finished with all the Telegram setup for our bot. Next introduce python-telegram-bot library:
pip install python-telegram-bot
python-telegram-bot library gives an awesome python interface to Telegram Bot API. It has a few reflections which makes the advancement of bots simple and clear. This library will deal with sending message to our API URL and get the reply or response from that URL. Here is the complete code for python-telegram-bot Github
- Below is the code to send Hello along with your username message to your Bot.
from telegram.ext import Updater, CommandHandler def hello(bot, update): update.message.reply_text( 'Hello {}'.format(update.message.from_user.first_name)) updater = Updater('YOUR TOKEN HERE') updater.dispatcher.add_handler(CommandHandler('hello', hello)) updater.start_polling() updater.idle()
- More Understanding about the code and making the Bot interactive will be in the next part of this series.
0 comments:
Post a Comment