I'm trying to send a message with bold, italic or other markdowns with telegram api post methods, but its not working. Can you tell what I doing wrong in this code snippet.
CID = #chat_id
message_text = "Hello *World!*" #Trying to format "World!" in bold
requests.post(f"https://api.telegram.org/bot<token>/sendMessage?chat_id={CID}&text={message_text}")
when I post above request my bot is sending Hello *World!* not Hello World! :(
Related
I am struggling so hard on the following problem:
As the title says I want to send a picture via the Telegram Bot API. This is the code everyone is suggesting:
params = {'chat_id': chatId, 'caption':"This is a caption"}
img = {'photo': open(imgpath, 'rb')}
status = requests.post(sendPhotoURL, data=params, files=img)
Unfortunately, that does not work for me.
I've found out that in requests.post data should be params in order to create/post the URL correctly. But I haven't found a solution for sending the picture via the URL.
This is the code that is working for me (so far):
params = {'chat_id': chatId, 'caption':"This is a caption"}
img = {'photo': open(imgpath, 'rb')}
status = requests.post(sendPhotoURL, params=params, files=img)
print (status.url, "responsed:\n", status.status_code, ":", status.text)
I know the picture should be sent as a multipart/form-data (see: https://core.telegram.org/bots/api#sendphoto), which should be done by setting the parameter files to img (which is a dictionary). By doing it this way, i still get 400 : {"ok":false,"error_code":400,"description":"Bad Request: there is no photo in the request"}, so apparantly the API wants me to put the image into the URL.
It's very possible that I'm misunderstanding the docs or that I'm doing something incredible stupid. It would be so nice if any geeks could help me out :D!
Thanks a lot!
PS: I'm sorry for any typos or grammar/spelling mistakes. English is not my first language :D
For example code that would return true for an embed menu posted by another bot, and false for if the bot just sends a simple text message.
Well For That All u need to do is
async def on_message(message):
if message.embed:
print("The MSG Is Embed")
Ref: Discord.py
Hope This Helps if it doesn't then ping me
I am trying to send a message containing a link through a Discord bot (something like: for more information click on the following link).
The problem is that everytime that I send it, Discord generetes an Embed for that message, which in a normal case would be nice, except i don't want it, as it looks very spammy.
I have tried stopping the embed with that embed=None, but it doesn't do it's job.
msg = await channel.send("Click on this link: https://somewhere.com", embed=None)
Acording to the docs, i should use embed=discord.Embed.Empty, but it is throwing me an error inside the lib files.
Any ideas? Maybe i could edit the message after sending it and try to remove the embed, but i don't think it will work...
Simply put the link between <>
msg = await channel.send("Click on this link: <https://somewhere.com>")
I am developing mobile with Xamarin and Node.js
and I want to post text using 'Editor'
In Xam.Android, Xam.iOS,
When I post text,
the result is
aa
bb
But In UWP
aabb
When I checked text that post's body in client,
all platforms show correct body
But, When I check text that post's body in node
Android, iOS's body is correct, UWP's body is incorrect
How I solve this?
Android, iOS's body is correct, UWP's body is incorrect
The Editor control is used to accept multi-line input. For my test, the line breaks for each platform are different.
IOS: \n
Android:\n
UWP:\r
So you could replace \r with \n in your client or make your node.js service support \r line break.
var Str = editor.Text.Replace("\r", "\n");
There is an image in the telegram docs showing a
Formatted message with an image and text under,
It's from TechCrunch.
I have tried to replicate this and failed.
How can one replicate this format.
I am using Python
def reply(msg=None, img=None):
if msg:
resp = urllib2.urlopen(BASE_URL + 'sendPhoto', urllib.urlencode({
'chat_id': str(chat_id),
'caption': msg,
})).read()
In case you are talking about this image here i'm pretty sure it was done with sendPhoto() method. Text can be placed under the image by using the optional caption parameter.
Telegram Bot API sendPhoto