Get information in chat

Hi :wave:,

It’s 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’ll be limitting this issue to contributors only.

… I guess it’s 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’m 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’s a problem with Javascript scope in that snippet. onConnectionEstablished tries to call setSessionid method on this. But it’s 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.