InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable

8 Comments

  • Joey
    Comment actions Permalink

    Hi there Juama-

    You mention this error is thrown when calling websocket.send, though I see that being called three times in the code you provided.May I ask you to please provide some more details? Thanks!

    Joey May
    Developer Support Engineer
    US | Zendesk
    joey@zendesk.com

    0
  • Chaiwat Wongchuen
    Comment actions Permalink

    try this :

    string UpdateAgent = "{\"payload\":{\"query\":\"mutation { updateAgentStatus(status: ONLINE) { node { id }}}\"},\"type\":\"request\",\"id\":2}";

    websocket.send(UpdateAgent);
     
    in your code ( ping agent to awake )
     
     
    0
  • Juanma Córdoba
    Comment actions Permalink

    Hi!

    first of all thanks for your help.

    My intention using the "Chat Conversations API" is the following (and I am not sure that my intention will be able to be executed with this API):

    I need an external software to: create chats in zopim, send messages as a user and receive the responses from an agent.

    I am able to authenticate and finally I am getting the websocket url. I thought that getting this websocket URL opens by defualt a chat in Zopim, but no.

    So my first intention is to create a chat in Zopim since my extrnal software, and send some text to this chat. And afterwards listen to this websocket to get the response of the agent and print it on my external software.

    This external software is a javascript project, this is the reason I am opening the websocket using

    var websocket = new WebSocket(
    "wss://chat-api.zopim.com:443/stream/0.1/graphql/xxxxxxx"
    );

    and not the example way "const webSocket = new WebSocket(websocket_url);".

    This is my full code:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Demo</title>
    <script src=""></script>
    </head>
    <body >
    </body>
    </html>

    <script>
    const REQUEST_ID = {
    MESSAGE_SUBSCRIPTION: 1,
    UPDATE_AGENT_STATUS: 2,
    SEND_MESSAGE: 3,
    GET_DEPARTMENTS: 4,
    TRANSFER_TO_DEPARTMENT: 5
    };
    const SUBSCRIPTION_DATA_SIGNAL = "DATA";
    const TYPE = {
    VISITOR: "Visitor"
    };


    var websocket = new WebSocket(
    "wss://chat-api.zopim.com:443/stream/0.1/graphql/xxxxx"
    );

    setInterval(() => {
    websocket.send(
    JSON.stringify({
    sig: "PING",
    payload: +new Date()
    })
    );
    console.log('keeping connection!');
    console.log('websocket', websocket);
    }, 5000);

    console.log(websocket);

    /***********************
    * Update agent status *
    ***********************/

    const updateAgentStatusQuery = {
    payload: {
    query: `mutation {
    updateAgentStatus(status: ONLINE) {
    node {
    id
    }
    }
    }`
    },
    type: "request",
    id: REQUEST_ID.UPDATE_AGENT_STATUS
    };
    websocket.send(
    JSON.stringify(
    updateAgentStatusQuery));

    console.log("[updateAgentStatus] Request sent");
    </script>

    Am I in the right way to what I whant to do?

    Thank you very much!!

    0
  • Bryan - Community Manager
    Comment actions Permalink

    Hi Juanma,

    It's not 100% clear what your solution needs but to clarify, the Chat Conversations API essentially lets you act as an agent. Whatever service is running and accessing the Chat Conversations API is for all intents and purposes an agent.

    You mention:

    I need external software to: create chats in zopim, send messages as a user, and receive the responses from an agent

    The Chat Conversations API is primarily used for integrating a chat bot as an agent, have that chat bot take and react to new chats coming into a Zendesk instance, and then possibly hand off the automated chat to a live agent. It doesn't sound like that's what you need, but hope this clarifies things enough for this situation.

    As for getting the actual code working, I'd take a step back and make sure the sample code in this tutorial works and then go from there: Getting started with the Chat Conversations API

    0
  • Bryan - Community Manager
    Comment actions Permalink

    In addition, there is also this other community post that maybe speaks better to your use case, where the Web Widget is used as a solution -- I thought I'd mention it here in case it might help:

    https://develop.zendesk.com/hc/en-us/articles/360001331787?page=1#comment_360001757167

     

    0
  • Juanma Córdoba
    Comment actions Permalink

    Hi guys!

    Thank you very much for your responses. I was wrong about the possibilities of the Conversational API.

    ¿Is there any possibilities to create chats to Zendesk agents from external software?

    Thanks again!

    0
  • Yu-Hsuan Chao
    Comment actions Permalink

    Hi Juanma,

    In response to your question

    ¿Is there any possibilities to create chats to Zendesk agents from external software?

     

    We are currently looking into possibilities of providing a solution for such use case. There are, however, no fixed timeline for production yet. Stay tuned!

    0
  • Juanma Córdoba
    Comment actions Permalink

    Thank you very much guys!

    This community helped me a lot.

    0

Please sign in to leave a comment.

Powered by Zendesk