Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
171 Vues

Hello all,


I am developing an Odoo extension, and I want to send a message from OdooBot to a given partner ID in Discuss. I am attempting to send myself such a message in the Odoo python shell here, and it seems to create a record, but in my browser window with the same DB, and verifying that the partner ID and channel IDs match, I still don't see the message. It even seems to be returned in a search of message records. What is missing for the message to show up properly?


I have assumed the logs about the push notification being deleted can be ignored. I have the chat window open, so it makes sense it would delete the push notification.

>>> odoobot_id = self.env.ref("base.partner_root").id

>>> channel = self.env["discuss.channel"].with_user(1).channel_get([8])

>>> channel.name

'OdooBot, Alex McColm'

>>> channel.message_post(body='HelloWorld!', author_id=odoobot_id, message_type="comment", subtype_xmlid="mail.mt_comment")

2025-10-23 17:54:34,848 1395 WARNING Odoo_Backup_2025-10-22__19-28-55.zip odoo.addons.mail.tools.web_push: Failed push notification https://fcm.googleapis.com/fcm/send/eJ32KjmxmoI:APA91bH8xugL7jxOtyXZqSGbBEaDcW5Ra0e1DD-PWnGWIzyNIhzYytvdrxwD-AvTI93P9XzKBYp8iQt8-_dS4gGywQ5K2EhjGRanBAK41ZobvUv8kx348nrmrqEoEhh51a6x_yJM0POr 410 - push subscription has unsubscribed or expired.

2025-10-23 17:54:35,054 1395 INFO Odoo_Backup_2025-10-22__19-28-55.zip odoo.models.unlink: User #1 deleted mail.push.device records with IDs: [4, 5]

mail.message(1097,)

>>> env['mail.message'].search_read(

...     [('model','=','discuss.channel'), ('res_id','=',4)],

...     ['id','author_id','body','message_type','subtype_id'],

...     limit=5, order='id desc'

... )

[{'id': 1097, 'author_id': (2, 'OdooBot'), 'body': Markup('<p>HelloWorld!</p>'), 'message_type': 'comment', 'subtype_id': (1, 'Discussions')}, {'id': 802, 'author_id': (2, 'OdooBot'), 'body': Markup('<p>Frontdesk Check-In: [redacted] (Foreseeson Technology)</p>'), 'message_type': 'comment', 'subtype_id': (1, 'Discussions')}, {'id': 47, 'author_id': (2, 'OdooBot'), 'body': Markup('<p>Hello,<br>Odoo\'s chat helps employees collaborate efficiently. I\'m here to help you discover its features.<br><b>Try to send me an emoji</b> <span class="o_odoobot_command">:)</span></p>'), 'message_type': 'comment', 'subtype_id': (1, 'Discussions')}]

>>>

Avatar
Ignorer
Meilleure réponse

Since your working with the odoo-bin shell:

Without committing to the database, nothing is going to be actually written to your database. Run

self.env.cr.commit()

after channel.message_post(...).

See also https://www.odoo.com/documentation/19.0/developer/reference/cli.html#shell-open-a-shell

Also, ensure you are actually a Member of the given Discuss Channel.

Avatar
Ignorer
Auteur

Thank you Christoph. This is what I was missing in shell testing.

When I was using this in my extension in a function called send_private_message_as_odoobot(), I had another bug, which I'll record here in case it is useful someday. In the shell, I was passing a partner ID properly, but in the extension I was passing an hr.employee record ID.

Publications associées Réponses Vues Activité
0
oct. 25
321
0
oct. 25
296
2
oct. 25
5852
2
oct. 25
603
2
oct. 25
828