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
Related
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! :(
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 trying to display an Animation Card using the Bot Framework with a text, GIF and buttons. It works perfectly on the bot emulator but does not show up on Messenger. Any ideas?
Code
/**Send the question with the level information if available, the index and the Math expression along with a countdown timer as GIF attachment */
let message = new builder.Message(session)
.text(level ? level + ' \n' + strings.question : strings.question, dialogData.index + 1, question.expression)
.addAttachment(
new builder.AnimationCard(session)
.media([{
profile: "image/gif",
url: "https://media.giphy.com/media/l3q2silev6exF53pu/200w.gif"
}])
.buttons(buttons)
// .toAttachment()
)
session.send(message)
On Emulator
On Messenger
Any ideas what might be off? Thank you in advance for your suggestions
UPDATE 1
This s the error on my console
{"error":{"message":"(#100) Param [elements][0][title] must be a non-empty UTF-8 encoded string","type":"OAuthException","code":100,"fbtrace_id":"CLEcx63w+4N"}}
You need to include a title with your animation card, Messenger requires all cards to include a title. Also, animation cards work a little differently in messenger in that they send a message with the .gif followed by a card with the title and the buttons, rather than having them all together in a nice card like in the emulator.
In your use case, I would use first line saying what level it is as the title, and the question as the subtitle. This text will appear below the gif instead of above it, though, so it's a little different layout than what you have now.
let message = new builder.Message(session)
.addAttachment(
new builder.AnimationCard(session)
.title(level ? level : 'Level 0')
.subtitle(strings.question)
.media([{
profile: "image/gif",
url: "https://media.giphy.com/media/l3q2silev6exF53pu/200w.gif"
}])
.buttons(buttons)
)
session.send(message)