crisp-im / node-crisp-api

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

Data validation error when sending message #50

Closed c-delouvencourt closed 1 year ago

c-delouvencourt commented 1 year ago

Hello,

We have an issue when sending picker message in a conversation, could you help us please ?

The request with : CrispClient.website.sendMessageInConversation

Capture d’écran 2023-02-14 à 10 55 16

The response :

{ "reason": "error", "message": "invalid_data", "code": 400, "data": { "namespace": "response", "message": "Got response error: data.type should be equal to one of the allowed values, data.type should be equal to one of the allowed values, data.type should be equal to one of the allowed values, data.type should be equal to one of the allowed values, data.content should have required property 'text', data.type should be equal to one of the allowed values, data.type should be equal to one of the allowed values, data.type should be equal to one of the allowed values, data should match some schema in anyOf" } }

baptistejamin commented 1 year ago

Hi there

baptistejamin commented 1 year ago

Can I ask how you are sending your picker?

baptistejamin commented 1 year ago

Are you pushing that message with the SDK?

baptistejamin commented 1 year ago

If so, could I see the full part of code relevant to that method?

c-delouvencourt commented 1 year ago

Hi Baptiste, we are sending the picker like that : https://hastebin.com/share/epiwuxeyud.javascript

baptistejamin commented 1 year ago

I think the issue is because of the type participant. Try with operator instead.

Baptiste Jamin

On 14 Feb 2023, at 11:04, Clément @.***> wrote:

Hi Baptiste, we are sending the picker like that : https://hastebin.com/share/epiwuxeyud.javascript

— Reply to this email directly, view it on GitHub https://github.com/crisp-im/node-crisp-api/issues/50#issuecomment-1429456725, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGTRQ4DZJWDEYC45ZBFVWDWXNKCTANCNFSM6AAAAAAU3K4U6Q. You are receiving this because you commented.

c-delouvencourt commented 1 year ago

Same issue with operator

baptistejamin commented 1 year ago

Can you please check all the types according to https://docs.crisp.chat/references/rest-api/v1/#send-a-message-in-conversation ?

-- Baptiste Jamin

On 14 Feb 2023, at 11:15, Clément @.***> wrote:

Same issue with operator

— Reply to this email directly, view it on GitHub https://github.com/crisp-im/node-crisp-api/issues/50#issuecomment-1429473102, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGTRQ4RBEPLCUVMEQQBLU3WXNLNJANCNFSM6AAAAAAU3K4U6Q. You are receiving this because you commented.

c-delouvencourt commented 1 year ago

I checked all the types are correct I think there is an error on the validation of the type field on your side

eliottvincent commented 1 year ago

There is no error on our side, your payload is invalid.

As stated in our API Reference, the text property is mandatory. This payload will work (I simply added the text property):

{
  "type": "picker",
  "from": "operator",
  "origin": "chat",
  "user": {
    "type": "participant",
    "nickname": "Edouard",
    "avatar": "https://i.imgur.com/4hh6oao.jpg"
  },
  "content": {
    "id": "aws_image_picker",
    "text": "Some text here",
    "choices": [
      {
        "value": "Connexion hektor",
        "label": "Connexion hektor",
        "selected": false
      },
      {
        "value": "Activer une passerelle de diffusion",
        "label": "Activer une passerelle de diffusion",
        "selected": false
      },
      {
        "value": "Personnaliser mon profil Hektor",
        "label": "Personnaliser ou modifier mon profil hektor",
        "selected": false
      },
      {
        "value": "exporter un bien ",
        "label": "Problème d'exportation d'un bien",
        "selected": false
      },
      {
        "value": "Autre question",
        "label": "Autre question",
        "selected": false
      }
    ]
  }
}