L
L
lexinti2020-12-11 00:58:38
Telegram
lexinti, 2020-12-11 00:58:38

How to use telegram bots externally?

Hello everyone, there is such a bot in telegrams @whoisdombot to check the entry of domains, please tell me if this bot can be used externally somehow? That is, through the Telegram services API, send requests to this bot and receive? Please tell me I really need to solve this problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-12-11
@shabelski89

Why complicate?
Here's whois with an open API.
Write a Bot, so be it written for you, you will bring prettiness.

import telebot
import requests

token_test = ""

bot = telebot.TeleBot(token_test)

api_url = 'http://ip-api.com/json/'


@bot.message_handler(commands=['start'])
def send_welcome(message):
    msg = bot.reply_to(message, """\
    Hello, I am WHOIS bot.
    Input IP or Hostname?
    """)
    bot.register_next_step_handler(msg, get_info)


def get_info(message):
    try:
        r = requests.get(api_url + message.text)
        info = r.text
    except Exception as E:
        print(E)
        info = 'Ooops'
    bot.send_message(chat_id=message.chat.id, text=info)


if __name__ == "__main__":
    try:
        bot.polling(none_stop=True)
    except Exception as Error:
        print(Error)

What do we have as a result? - 5fd2a01c879c3486813247.png
I hope you don't need to explain how to translate the json string into a python dictionary? and take the required field from there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question