Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
480 Vizualizări

I am building a mobile app and using Odoo as the backend. I want to integrate Odoo’s built-in Discuss module so that users can chat with each other inside the app — similar to how messaging works in the Odoo web Discuss module.

Example use case:

User A sends a message to User B → It should be stored and visible in their chat history in the mobile app (just like mail.message or mail.channel works in Odoo Discuss).



Imagine profil
Abandonează
Cel mai bun răspuns
Technical Approach


Step 1: Create or Fetch a 1-to-1 Mail Channel

Odoo uses mail.channel for conversations. For private messages between two users, you can reuse an existing private channel or create a new one .

# Create or fetch private chat channel between two users
channel = self.env['mail.channel'].channel_get([user_a_id, user_b_id])
channel_id = channel['id']

Or via JSON-RPC in your mobile app:

{
  "model": "mail.channel",
  "method": "channel_get",
  "args": [[user_a_id, user_b_id]]
}

This will return a dictionary with the channel ID for the private chat.


Step 2: Send a Message to the Channel

Once you have the channel_id, post a message using channel_message_post.

self.env['mail.channel'].browse(channel_id).message_post(
    body="Hello, User B!",
    message_type="comment",
    subtype_xmlid="mail.mt_comment"
)

Or via JSON-RPC:

{
  "model": "mail.channel",
  "method": "message_post",
  "args": [],
  "kwargs": {
    "body": "Hello, User B!",
    "message_type": "comment",
    "subtype_xmlid": "mail.mt_comment"
  },
  "context": {
    "default_model": "mail.channel",
    "default_res_id": channel_id
  }
}
Step 3: Fetch Messages from the Channel

Use mail.message to fetch messages linked to the channel:

messages = self.env['mail.message'].search_read([
    ('model', '=', 'mail.channel'),
    ('res_id', '=', channel_id)
], ['body', 'date', 'author_id'])

This will give the chat history for that private conversation.


Step 4: Push Notifications (Optional)

You can use Odoo's built-in bus for real-time communication ( bus.Bus ). But for mobile apps, it's better to implement a polling mechanism or integrate Firebase / OneSignal for push notifications when a new message is posted.

Required Odoo Modules

Make sure the following are installed:

  • mail (core messaging)
  • bus (for real-time notifications)
  • im_livechat (if live chat is also needed, optional)
Permissions & Access

Ensure users in your app are mapped to Odoo users with:

  • Access to mail.channel, mail.message
  • Proper record rules (restricting access to only their own cats)
  • If you want guests to chat, consider creating special partner records or portal users.
On the Mobile App Side

Build API calls or JSON-RPC requests to:

  • mail.channel.channel_get([user_a_id, user_b_id])
  • mail.channel.message_post(...)
  • mail.message.search_read(...)

You can also extend Odoo Controllers to expose REST APIs if needed ( /mail/chat/send , /mail/chat/history , etc.).


Compatible with Odoo Licensing
  • Odoo Enterprise or Community — both support mail and mail.channel.
  • You do not need to modify the core Discuss module . You're using exposed models/controllers the way Odoo does.
  • Your mobile app is acting as a frontend, and all business logic remains in Odoo = legal and safe.

Example: Flow API
  1. Login
  2. Get channel for user IDs
  3. Send message to channel
  4. Read messages for channel
  5. (Optional) Push notification via FCM


Thanks & Regards,

Email: contact@datainteger.com

Imagine profil
Abandonează