Create message not working for ts-sdk

When trying to create a message using the following code:

const { text } = Object.fromEntries(new FormData(e.target as HTMLFormElement));

    const query = createQuery(createMessage, {
      subChannelId: "simple-chat-demo",
      dataType: "text",
      data: {
        text: "hello world",
      },
      tags: ["tag1", "tag2"],
      metadata: {
        data: "anything",
      },
    });

    runQuery(query, ({ data: message, ...options }) => console.log(message, options));

I’m getting the following error in the response of the POST request:

{
    "status": "error",
    "message": "Parameters validation error!",
    "code": 500000,
    "data": {
        "detail": [
            "The 'referenceId' field is required."
        ]
    }
}

The code is directly taken from the docs for creating text messages.. What am I doing wrong here?

Hi @PulkitVyas

Thanks for your inquiry. May I confirm which TS SDK version you’re using?

Amity Support

The ts-sdk version is 0.0.1-beta.40

Hi @PulkitVyas can you please try changing subChannelId → channelId, let us know if it works.

Thank you

Doesn’t work, getting type error in the editor and when trying to send the message getting this error in the request response:

{
    "status": "error",
    "message": "Parameters validation error!",
    "code": 500000,
    "data": {
        "detail": [
            "The 'messageFeedId' field is required.",
            "The 'referenceId' field is required."
        ]
    }
}

@amitysupport I am also having this issue, using the latest beta version of this package. I believe it is because of this line in /src/message/api/createMessage.ts :
image

It sets the referenceId to undefined in effect (uniqueId is never defined, see line 11), so it is never sent with the API request, and hence this fails. I have tried editing the package code to manually generate a uniqueId, and then the request successfully executes.

Is there any timeline available on when this issue will be fixed, as it is a fairly important part of the package?

@travisreynolds

Hey, thank you for pointing out the issue. I can fix it as part of this release which would be 21 or 22 March 2023.

I’ve created a ticket for it, I’ll keep you updated if there is a change in this plan.

C.C @PulkitVyas @amitysupport

1 Like

While waiting the fix, try to do

import { enableCache } from '@amityco/ts-sdk';

enableCache();

somewhere at the startup

1 Like

@cijin any updates on the release?

@PulkitVyas The code has passed QA. Will be released this week.

2 Likes