Get information in chat

Hi :wave:,

It鈥檚 my first question here, happy to meet you!

Reading some (unfortunately closed) topics (such as Custom fields for chat 路 Issue #233 路 zammad/zammad 路 GitHub), it seems the right way to send user info when the connection is established with chat is to use:

const chat = new ZammadChat({
    ...options
});

chat.onConnectionEstablished = (data) => {
    ZammadChat.prototype.onConnectionEstablished.call(this, data);

    chat.send('chat_session_notice', {
        session_id: chat.sessionId,
        message: 'Your message',
    });
};

Still it seems it does not work anymore. For instance, when I copy/paste the code, I get this error:

chat.min.js:1 Uncaught TypeError: this.setSessionId is not a function
    at HTMLDocument.e.onConnectionEstablished (chat.min.js:1)
    at eval (eval at chat.onConnectionEstablished (inscription:1), <anonymous>:1:46)
    at e.chat.onConnectionEstablished (inscription:43)
    at e.onWebSocketMessage (chat.min.js:1)
    at Object.onMessage (chat.min.js:1)
    at WebSocket.ws.onmessage (chat.min.js:1)

At this line:

    ZammadChat.prototype.onConnectionEstablished.call(this, data);

Since the last answer on this issue is:

Please do not post technical questions on github but our community instead.
As this issue is quite old and to reduce bumps I鈥檒l be limitting this issue to contributors only.

鈥 I guess it鈥檚 the right place to ask.

How can I send message from chat client to zammad? (the goal is to send user infos)

Let me know if I can improve my question!

Welcome :wave:
I鈥檓 switching the category of this thread to development hoping that one of our devs like e.g. @mantas is able to help you better. :pray:

1 Like

Looks like there鈥檚 a problem with Javascript scope in that snippet. onConnectionEstablished tries to call setSessionid method on this. But it鈥檚 this context is wrong. Did you try to pass chat instead?

1 Like

Thank you @mantas !!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.