crisp-im / node-crisp-api

:zap: Crisp API Node Wrapper
https://docs.crisp.chat/guides/rest-api/
MIT License
99 stars 38 forks source link

Error in readMessages #29

Closed ririko5834 closed 3 years ago

ririko5834 commented 3 years ago

Hi, I created chatbot and I want to mark messages that are commands (includes specific keywords) as read, to prevent crisp from sending me email notifications when user used that command and bot replied when I am offline.

I have this code in message:send event:

let arr = [];
arr.push(message.fingerprint)
CrispClient.websiteConversations.readMessages(message.website_id, message.session_id, {
from : "operator", 
origin : "chat",
fingerprints: arr

}
)  .then((data) => {
    console.info("Read message.", data);
  })
  .catch((error) => {
    console.error("Failed reading message:", error);
  });

but I am getting this in console

Failed reading message: {
  reason: 'error',
  message: 'invalid_data',
  code: 400,
  data: {
    namespace: 'response',
    message: "Got response error: data should have required property '.origin'"
  }
}

What I did wrong?

ririko5834 commented 3 years ago

Btw, is it possible to mark current conversation as resolved (and send transcript to the user's email) using this wrapper?

eliottvincent commented 3 years ago

Hello!

In your example you are using the method like this: websiteConversations.readMessages(websiteId, sessionId, data), this is wrong. Please check the README, the prototype is websiteConversations.readMessages(websiteId, sessionId, from, origin, fingerprints).

Yes you can resolve the conversation via websiteConversations.setState. Check the README for more details. It's possible to send a transcript via API (https://docs.crisp.chat/api/v1/#website-website-conversation-post-3) but not via this wrapper. You can do a PR if you want.

ririko5834 commented 3 years ago

Ok, I think that transcript method should be added to this wrapper