Reputation: 1051
import telebot
from telebot import types
TOKEN = ''
bot = telebot.TeleBot(TOKEN) #create a new Telegram Bot object
tg_markup = types.InlineKeyboardMarkup(row_width=2)
tg_itembtn1 = types.InlineKeyboardButton("👉 GO 👈", 'http://google.it')
tg_markup.add(tg_itembtn1)
tg_message_to_send = "Hello!\n\n"
tg_message_to_send += "This is a test"
tg_message_to_send = "Title\n\n"
tg_message_to_send += "🔺Other text: €\n"
tg_message_to_send += "🏷Text #2: €\n"
tg_message_to_send += "Text #3 %\n\n"
tg_message_to_send += "► https://bit . ly/dsfini"
tg_message_to_send += "<a href='https://www.collinsdictionary.com/images/thumb/tree_267376982_250.jpg?version=4.0.200'>‍</a>"
bot.send_message('CHAT_ID_HERE', tg_message_to_send, parse_mode = 'HTML', reply_markup = tg_markup, disable_web_page_preview=False)
I would like to send a message to a Telegram group containing a link and an image attached to it. The problem is that the above code doesn't send the image. After many tries, I found that if I omit the line containing the link https://bit . ly/dsfini, the image is being sent.
How can I send both the link and the image?
Note: I insert a space in the link due to stackoverflow policy.
Upvotes: 1
Views: 2227
Reputation: 7030
Most TG clients will display a preview for the first link that's included in the message. So moving that hidden hyperref to the start of the message should do the trick.
EDIT
Note that tg_message_to_send = "Title\n\n"
overrides tg_message_to_send
. Changing to
tg_message_to_send = "Hello!\n\n"
tg_message_to_send += "<a href='https://www.collinsdictionary.com/images/thumb/tree_267376982_250.jpg?version=4.0.200'>‍</a>"
tg_message_to_send += "This is a test"
tg_message_to_send += "Title\n\n"
tg_message_to_send += "🔺Other text: €\n"
tg_message_to_send += "🏷Text #2: €\n"
tg_message_to_send += "Text #3 %\n\n"
tg_message_to_send += "► https://bit . ly/dsfini"
or simply
tg_message_to_send = (
"Hello!\n\n"
"<a href='https://www.collinsdictionary.com/images/thumb/tree_267376982_250.jpg?version=4.0.200'>‍</a>"
"This is a test"
"Title\n\n"
"🔺Other text: €\n"
"🏷Text #2: €\n"
"Text #3 %\n\n"
"► https://bit . ly/dsfini"
)
gives tha desired result for me.
Upvotes: 2