340 | def slave_message_link(self, msg: Message, tg_dest: TelegramChatID, msg_template: str, reactions: str, |
341 | old_msg_id: OldMsgID = None, |
342 | target_msg_id: Optional[TelegramMessageID] = None, |
343 | reply_markup: Optional[ReplyMarkup] = None, |
344 | silent: bool = False) -> telegram.Message: |
345 | self.bot.send_chat_action(tg_dest, ChatAction.TYPING) |
346 | |
347 | assert isinstance(msg.attributes, LinkAttribute) |
348 | attributes: LinkAttribute = msg.attributes |
349 | |
350 | thumbnail = urllib.parse.quote(attributes.image or "", safe="?=&#:/") |
351 | thumbnail = "<a href="\"%s\"">🔗</a>" % thumbnail if thumbnail else "🔗" |
352 | text = "%s <a href="\"%s\"">%s</a>\n%s" % \ |
353 | (thumbnail, |
354 | urllib.parse.quote(attributes.url, safe="?=&#:/"), |
355 | html.escape(attributes.title or attributes.url), |
356 | html.escape(attributes.description or "")) |
357 | |
358 | if msg.text: |
359 | text += "\n\n" + self.html_substitutions(msg) |
360 | if old_msg_id: |
361 | return self.bot.edit_message_text(text=text, chat_id=old_msg_id[0], message_id=old_msg_id[1], |
362 | prefix=msg_template, suffix=reactions, parse_mode='HTML', |
363 | reply_markup=reply_markup) |
364 | else: |
365 | return self.bot.send_message(chat_id=tg_dest, |
366 | text=text, |
367 | prefix=msg_template, suffix=reactions, |
368 | parse_mode="HTML", |
369 | reply_to_message_id=target_msg_id, |
370 | reply_markup=reply_markup, |
371 | disable_notification=silent) |