Skip to Content
Menu
This question has been flagged
3 Replies
3284 Views

Hello, is there any way to change the name of the operator in live chat box?

If yes, do you know some articles on how to do it?

Your help is greatly appreciated. Thanks :)

Avatar
Discard
Author

I tried to override the methods but it returns the operator name and visitor the same display name. Any idea?

im_livechat_channel.py

@api.model

def get_livechat_info(self, channel_id, username='Visitor'):

info = super(ImLivechatChannel, self).get_livechat_info(channel_id, username)

info['options']['chat_author_nickname'] = self.env.user.nickname

return info

im_livechat.js

add_message: function (data, options) {

var msg = {

id: data.id,

attachment_ids: data.attachment_ids,

author_id: data.author_id,

body: data.body,

date: moment(time.str_to_datetime(data.date)),

is_needaction: false,

is_note: data.is_note,

customer_email_data: []

};

// Compute displayed author name or email

// msg.displayed_author = msg.author_id && msg.author_id[1] ||

// this.options.default_username;

if (msg.author_id && msg.author_id[1]) {

msg.displayed_author = this.options.chat_author_nickname;

}

else {

msg.displayed_author = this.options.default_username;

}

// Compute the avatar_url

msg.avatar_src = this.server_url;

if (msg.author_id && msg.author_id[0]) {

msg.avatar_src += "/web/image/res.partner/" + msg.author_id[0] + "/image_small";

} else {

msg.avatar_src += "/mail/static/src/img/smiley/avatar.jpg";

}

if (options && options.prepend) {

this.messages.unshift(msg);

} else {

this.messages.push(msg);

}

},

Best Answer

Not sure but maybe this app may help you to change the name of the operator in live chat.

Avatar
Discard
Author

thanks for your help but I am looking for an answer/articles which helps me to do my code.

Best Answer

There now is an option in your Odoo profile to input a preferred name in the "Online Chat Name" field on your profile (top right of Odoo screen).
select My Profile > Preferences > Online Chat Name

Avatar
Discard
Author Best Answer

Rewriting the code.


python

class ImLivechatChannel(models.Model):
    _inherit = "im_livechat.channel"
    @api.model
    def get_livechat_info(self, channel_id, username='Visitor'):
        info = super(ImLivechatChannel, self).get_livechat_info(channel_id, username)
        info['options']['chat_author_nickname'] = self.env.user.nickname
        return info




js

add_message: function (data, options) {
        var msg = {
            id: data.id,
            attachment_ids: data.attachment_ids,
            author_id: data.author_id,
            body: data.body,
            date: moment(time.str_to_datetime(data.date)),
            is_needaction: false,
            is_note: data.is_note,
            customer_email_data: []
        };
        
        // Compute displayed author name or email
        // msg.displayed_author = msg.author_id && msg.author_id[1] ||
        //                        this.options.default_username;
        if (msg.author_id && msg.author_id[1]) {
           msg.displayed_author = this.options.chat_author_nickname;
        }
        else {
           msg.displayed_author = this.options.default_username;
        }
        // Compute the avatar_url
        msg.avatar_src = this.server_url;
        if (msg.author_id && msg.author_id[0]) {
            msg.avatar_src += "/web/image/res.partner/" + msg.author_id[0] + "/image_small";
        } else {
            msg.avatar_src += "/mail/static/src/img/smiley/avatar.jpg";
        }
        if (options && options.prepend) {
            this.messages.unshift(msg);
        } else {
            this.messages.push(msg);
        }
    },
Avatar
Discard
Related Posts Replies Views Activity
1
Jan 23
654
1
Nov 15
6134
0
Nov 23
489
3
Dec 23
5737
0
Dec 21
1503