itpp-labs / sync-addons

**Sync 🪬 Studio**
https://t.me/sync_studio
143 stars 136 forks source link

sync_telegram: error when the bot is blocked #278

Open trojikman opened 3 years ago

trojikman commented 3 years ago

Steps to reproduce the error:

  1. Start messaging with the bot via telegram and block it after that
  2. Try to send a message via Odoo with the user without Administration/Settings access rights Result: You'll see something like that: Screenshot from 2021-08-23 17-20-26

If we try to send the message via the user with Administration/Settings access rights we'll get this error:

``` Odoo Server Error Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_http.py", line 237, in _dispatch result = request.dispatch() File "/usr/lib/python3/dist-packages/odoo/http.py", line 683, in dispatch result = self._call_function(**self.params) File "/usr/lib/python3/dist-packages/odoo/http.py", line 359, in _call_function return checked_call(self.db, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 94, in wrapper return f(dbname, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/http.py", line 347, in checked_call result = self.endpoint(*a, **kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 912, in __call__ return self.method(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 531, in response_wrap response = f(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1377, in call_kw return self._call_kw(model, method, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1369, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/api.py", line 396, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/api.py", line 383, in _call_kw_multi result = method(recs, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_channel.py", line 416, in message_post message = super(Channel, self.with_context(mail_create_nosubscribe=True)).message_post(message_type=message_type, moderation_status=moderation_status, **kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_thread.py", line 1888, in message_post self._notify_thread(new_message, values, **notif_kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_channel.py", line 542, in _notify_thread super(Channel, self)._notify_thread(message, msg_vals=msg_vals, **kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/sms/models/mail_thread.py", line 236, in _notify_thread recipients_data = super(MailThread, self)._notify_thread(message, msg_vals=msg_vals, **kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_thread.py", line 2135, in _notify_thread self._notify_record_by_inbox(message, rdata, msg_vals=msg_vals, **kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_thread.py", line 2153, in _notify_record_by_inbox message.write({'channel_ids': [(6, 0, channel_ids)]}) File "/usr/lib/python3/dist-packages/odoo/addons/base_automation/models/base_automation.py", line 348, in write action._process(records, domain_post=domain_post) File "/usr/lib/python3/dist-packages/odoo/addons/base_automation/models/base_automation.py", line 273, in _process raise e File "/usr/lib/python3/dist-packages/odoo/addons/base_automation/models/base_automation.py", line 270, in _process self.action_server_id.sudo().with_context(**ctx).run() File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions.py", line 629, in run res = runner(run_self, eval_context=eval_context) File "/usr/lib/python3/dist-packages/odoo/addons/website/models/ir_actions.py", line 61, in _run_action_code_multi res = super(ServerAction, self)._run_action_code_multi(eval_context) File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions.py", line 498, in _run_action_code_multi safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True) # nocopy allows to return 'action' File "/usr/lib/python3/dist-packages/odoo/tools/safe_eval.py", line 346, in safe_eval raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr)) Exception The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/http.py", line 639, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/usr/lib/python3/dist-packages/odoo/http.py", line 315, in _handle_exception raise exception.with_traceback(None) from new_cause ValueError: : ": "Forbidden: bot was blocked by the user" while evaluating '\ndef handle_db(records):\n # records are instances of mail.message\n for mail_message in records:\n for channel in mail_message.channel_ids:\n if channel.channel_type != \'telegram\':\n continue\n channel_link = channel.search_links(TG_CHAT_CHANNEL_REL)\n if not channel_link:\n continue\n\n telegram_user_ref = channel_link.external\n #channel_link = get_link(TG_CHAT_CHANNEL_REL, telegram_user_ref)\n\n if not mail_message.author_id.search_links(TG_PARTNER_REL) and mail_message.author_id.id != odoobot_id:\n log("MESSAGE from odoo: channel_id %s - author_id %s - attachment_ids: %s - message_text: %s" % (mail_message.res_id, mail_message.author_id.id, mail_message.attachment_ids, mail_message.body), LOG_DEBUG)\n\n if mail_message.body:\n message_html = "%s\\n\\n%s" % (mail_message.body, mail_message.author_id.name)\n telegram.sendMessage(telegram_user_ref, message_html, parse_mode=\'HTML\')\n\n if mail_message.attachment_ids:\n for attach in mail_message.attachment_ids:\n log("ATTACHMENT from odoo: attach.id %s - name %s" % (attach.name, attach.id), LOG_INFO)\n\n if attach.mimetype and "/" in attach.mimetype and attach.mimetype.split("/")[0] == "image":\n if attach.file_size < telegram.MAX_SIZE_IMAGE:\n telegram.sendPhoto(telegram_user_ref, attach.datas)\n else:\n channel.message_post(body="You cannot send more than 10 MB for photos.",\n author_id=odoobot_id, message_type="comment", subtype_xmlid="mail.mt_comment")\n else:\n if attach.file_size < telegram.MAX_SIZE_DOCUMENT:\n telegram.sendDocument(telegram_user_ref, attach.name, attach.datas)\n else:\n channel.message_post(body="You cannot send more than 50 MB for documents.",\n author_id=odoobot_id, message_type="comment", subtype_xmlid="mail.mt_comment")\n\n\n\n \nEXECUTION_RESULT_ = handle_db(*EXECUTION_ARGS_, **EXECUTION_KWARGS_)\n '" while evaluating 'env["sync.trigger.automation"].browse(4).sudo().start(records)' ```

Expected behavior: in cases when the user blocks the Bot in Odoo we need to understand what's happened without any errors

trojikman commented 3 years ago

via Hubstaff User: Denis Mudarisov

Project: sync-addons - https://app.hubstaff.com/projects/1618283 Date Range: 08/19/21 - 08/19/21 Work session total: 0:39:30 Billable: Yes

Grand total: 0:39:30

trojikman commented 3 years ago

via Hubstaff User: Denis Mudarisov

Project: sync-addons - https://app.hubstaff.com/projects/1618283 Date Range: 08/09/21 - 08/20/21 Work session total: 2:35:03 Billable: Yes

Grand total: 3:14:33

trojikman commented 3 years ago

More detailed error:

``` Odoo Server Error Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_http.py", line 237, in _dispatch result = request.dispatch() File "/usr/lib/python3/dist-packages/odoo/http.py", line 683, in dispatch result = self._call_function(**self.params) File "/usr/lib/python3/dist-packages/odoo/http.py", line 359, in _call_function return checked_call(self.db, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 94, in wrapper return f(dbname, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/http.py", line 347, in checked_call result = self.endpoint(*a, **kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 912, in __call__ return self.method(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 531, in response_wrap response = f(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1389, in call_kw return self._call_kw(model, method, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1381, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/api.py", line 396, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/api.py", line 383, in _call_kw_multi result = method(recs, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_channel.py", line 426, in message_post message = super(Channel, self.with_context(mail_create_nosubscribe=True, mail_post_autofollow=False)).message_post(message_type=message_type, moderation_status=moderation_status, **kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_thread.py", line 1896, in message_post self._notify_thread(new_message, values, **notif_kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_channel.py", line 552, in _notify_thread super(Channel, self)._notify_thread(message, msg_vals=msg_vals, **kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/sms/models/mail_thread.py", line 238, in _notify_thread recipients_data = super(MailThread, self)._notify_thread(message, msg_vals=msg_vals, **kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_thread.py", line 2143, in _notify_thread self._notify_record_by_inbox(message, rdata, msg_vals=msg_vals, **kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_thread.py", line 2161, in _notify_record_by_inbox message.write({'channel_ids': [(6, 0, channel_ids)]}) File "/usr/lib/python3/dist-packages/odoo/addons/base_automation/models/base_automation.py", line 348, in write action._process(records, domain_post=domain_post) File "/usr/lib/python3/dist-packages/odoo/addons/base_automation/models/base_automation.py", line 273, in _process raise e File "/usr/lib/python3/dist-packages/odoo/addons/base_automation/models/base_automation.py", line 270, in _process self.action_server_id.sudo().with_context(**ctx).run() File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions.py", line 632, in run res = runner(run_self, eval_context=eval_context) File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions.py", line 501, in _run_action_code_multi safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True) # nocopy allows to return 'action' File "/usr/lib/python3/dist-packages/odoo/tools/safe_eval.py", line 346, in safe_eval raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr)) Exception The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/http.py", line 639, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/usr/lib/python3/dist-packages/odoo/http.py", line 315, in _handle_exception raise exception.with_traceback(None) from new_cause ValueError: : ": "Forbidden: bot was blocked by the user" while evaluating '\ndef handle_db(records):\n # records are instances of mail.message\n for mail_message in records:\n for channel in mail_message.channel_ids:\n if channel.channel_type != \'multi_livechat_telegram\':\n continue\n channel_link = channel.search_links(TG_CHAT_CHANNEL_REL)\n if not channel_link:\n continue\n\n telegram_user_ref = channel_link.external\n #channel_link = get_link(TG_CHAT_CHANNEL_REL, telegram_user_ref)\n\n if not mail_message.author_id.search_links(TG_PARTNER_REL) and mail_message.author_id.id != odoobot_id:\n log("MESSAGE from odoo: channel_id %s - author_id %s - attachment_ids: %s - message_text: %s" % (mail_message.res_id, mail_message.author_id.id, mail_message.attachment_ids, mail_message.body), LOG_DEBUG)\n\n if mail_message.body:\n message_html = "%s\\n\\n%s" % (mail_message.body, mail_message.author_id.name)\n telegram.sendMessage(telegram_user_ref, message_html, parse_mode=\'HTML\')\n\n if mail_message.attachment_ids:\n for attach in mail_message.attachment_ids:\n log("ATTACHMENT from odoo: attach.id %s - name %s" % (attach.name, attach.id), LOG_INFO)\n\n if attach.mimetype and "/" in attach.mimetype and attach.mimetype.split("/")[0] == "image":\n if attach.file_size < telegram.MAX_SIZE_IMAGE:\n telegram.sendPhoto(telegram_user_ref, attach.datas)\n else:\n channel.message_post(body="You cannot send more than 10 MB for photos.",\n author_id=odoobot_id, message_type="comment", subtype_xmlid="mail.mt_comment")\n else:\n if attach.file_size < telegram.MAX_SIZE_DOCUMENT:\n telegram.sendDocument(telegram_user_ref, attach.name, attach.datas)\n else:\n channel.message_post(body="You cannot send more than 50 MB for documents.",\n author_id=odoobot_id, message_type="comment", subtype_xmlid="mail.mt_comment")\n\n\n\n \nEXECUTION_RESULT_ = handle_db(*EXECUTION_ARGS_, **EXECUTION_KWARGS_)\n '" while evaluating 'env["sync.trigger.automation"].browse(4).sudo().start(records)' ```
trojikman commented 3 years ago

via Hubstaff User: Denis Mudarisov

Project: sync-addons - https://app.hubstaff.com/projects/1618283 Date Range: 08/20/21 - 08/23/21 Work session total: 1:01:24 Billable: Yes

Grand total: 4:15:57

trojikman commented 3 years ago

via Hubstaff User: Denis Mudarisov

Project: sync-addons - https://app.hubstaff.com/projects/1618283 Date Range: 08/24/21 - 08/24/21 Work session total: 0:40:47 Billable: Yes

Grand total: 4:56:44

trojikman commented 3 years ago

via Hubstaff User: Denis Mudarisov

Project: sync-addons - https://app.hubstaff.com/projects/1618283 Date Range: 08/24/21 - 08/24/21 Work session total: 0:00:52 Billable: Yes

Grand total: 4:57:36

trojikman commented 3 years ago

via Hubstaff User: Denis Mudarisov

Project: sync-addons - https://app.hubstaff.com/projects/1618283 Date Range: 08/26/21 - 08/26/21 Work session total: 0:19:16 Billable: Yes

Grand total: 5:16:52