Creating an Automated Bot Using Python and Telegram (Part 2)

In Part-1, We learn from very beginning that how to create a bot using Telegram and python-telegram-bot,

In this tutorial, we will code a simple bot that will reply with the same message that you will send to the bot. we can simply name it as a "auto-reply" bot.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python
import telegram
from telegram.error import NetworkError, Unauthorized
from time import sleep

update_id = None

def main():
    global update_id
    bot = telegram.Bot('TOKEN')
    echo(bot)

def echo(bot):

    global update_id
    for update in bot.get_updates(offset=update_id, timeout=10):
        update_id = update.update_id + 1

        if update.message:  # your bot can receive updates without messages
            # Reply to the message
            update.message.reply_text(update.message.text)

if __name__ == '__main__':
main()  

Some Other Techniques for Making Interesting Bot
  • Like you can use any API that is taking some parameters and returning you the specific response, get the response make as you want and you can use it with a telegram bot. 



  • What i have done is that i have explored an API that takes mathematical sums and returns the answer, i create a simple telegram bot named as MathsMagic Bot, after then i take input from the user through that bot, passes the input to that API and show the response to the user. Same approach can be applied to Cryptocurrency rates and other useful things.
  • Another idea was to create an Image Analytics Bot, that takes an image from the user, pass that image to API or tool that will perform analysis on it and gives back the result, Post the result as output to that bot.
This is how you can use Telegram bot with multiple APIs and tools and create your own interesting Bot. Go for it and wait for the third tutorial in which we will explore the Telegram Bot further and see its other features also like creating a menu inside your bot and creating a group based Bot and manymore.

0 comments:

Post a Comment