I have been trying since the morning but earlier there were errors, so i had the direction but now there is no error and even not a warning too..
How code looks like :
import requests
def send_msg(text):
token = "TOKEN"
chat_id = "CHATID"
url_req = "https://api.telegram.org/bot" + token + "/sendMessage" + "?chat_id=" + chat_id + "&text=" + text
results = requests.get(url_req)
print(results.json())
send_msg("hi there 1234")
What is expected output :
It should send a text message
What is the current output :
It prints nothing
It would be great help is someone helps, Thank you all
Edit : 2
As the below dependancies were not installed, it was not capable of sending the text .
$ pip install flask
$ pip install python-telegram-bot
$ pip install requests
Now can somebody help me with sendPhoto please? I think it is not capable of sending image via URL, Thank you all
**Edit 3 **
I found a image or video sharing url from here but mine image is local one and not from the remote server
3
Answers
This works for me:
There is nothing wrong with your code. All you need to do is proper indentation.
Run the below code. It will work fine :
To send a picture might be easier using bot library :
bot.sendPhoto(chat_id, 'URL')
Note : It’s a good idea to configure your editor to make tabs and spaces visible to avoid such errors.
Here is an example that correctly encoded URL parameters using the popular
requests
library. This is a simple method if you simply want to send out plain-text or Markdown-formatted alert messages.For full example and more information on how to set up a Telegram bot for a group chat, see README here.
Below is also the same using asyncio and
aiohttp
client, with throttling the messages by catching HTTP code 429. Telegram will kick out the bot if you do not throttle correctly.