-1

Folks,

Does anyone have any examples of executing an oracle query and sending the message via telegram bot in python?

1 Answers1

0

I can only answer half of your question, which is sending the message via telegram bot in python.

Creating your bot

  1. On Telegram, search @ BotFather, send him a “/start” message

  2. Send another “/newbot” message, then follow the instructions to setup a name and a username

  3. Your bot is now ready, be sure to save a backup of your API token, and correct, this API token is your bot_token

Getting your Chat id

  1. On Telegram, search your bot (by the username you just created), press the “Start” button or send a “/start” message

  2. Open a new tab with your browser, enter https://api.telegram.org/bot/getUpdates , replace with your API token, press enter and you should see something like this:

{"ok":true,"result":[{"update_id":77xxxxxxx,
"message":{"message_id":550,"from":{"id":34xxxxxxx,"is_bot":false,"first_name":"Man Hay","last_name":"Hong","username":"manhay212","language_code":"en-HK"}

Look for “id”, for instance, 34xxxxxxx above is my chat id. Look for yours and put it as your bot_chatID in the code above

Python Code:

import requests

def telegram_bot_sendtext(bot_message):

    bot_token = '<INSERT_API_KEY>'
    bot_chatID = '<INSERT_CHATID>'
    send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + bot_message

    response = requests.get(send_text)

    return response.json()

test = telegram_bot_sendtext("Testing Telegram bot")
print(test)
dswdsyd
  • 576
  • 4
  • 12