Hi. I’m making a bot for telegram. I need the functionality to delete a message and to send local files, and since I’m not an expert on python, I have to modify the site packages directly.
So in rasa\core\channels\telegram.py I did the following changes:
-
Added
("delete",): "delete_message",and("local",): "send_local_document",to thesend_functionsdictionary in the functionTelegramOutput.send_custom_json. -
Added
message_id=msg.message_idto every call ofUserMessagein the functionTelegramInput.message.
In telegram\bot.py i added:
def send_local_document(self, chat_id, document, filename=None, caption=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, parse_mode=None, thumb=None, **kwargs):
self.send_document(chat_id, open(document, 'rb'), filename, caption, disable_notification, reply_to_message_id, reply_markup, timeout, parse_mode, thumb)
With these changes I can use
attachment = {"local": path}
dispatcher.utter_custom_json(attachment)
to upload a file to telegram and send it and I can use
ldte = tracker.events_after_latest_restart()
for item in reversed(ldte):
if item["event"] == "user":
if "message_id" in item:
attachment = {"delete":int(item["message_id"])}
dispatcher.utter_custom_json(attachment)
break
to get an user message id and delete it (the second “if” is to prevent errors in tests using shell or interactive). This works, but overwriting the packages looks like a problematic idea. So what would be the correct way to customize a channel to add this functionality?