Issue integrating web-sdk in react-native application

Currently, our application is running on React Native version 0.63.5 and Node version 14.17.6. We have integrated Amity Web SDK for live chat functionality. However, we are encountering difficulties as there is insufficient documentation available on the process of creating a user, authenticating, authorizing, creating a channel, and initiating a chat.

we would be grateful if you could provide us with detailed guidance on the entire process of user login to the chat functionality.

The below code not getting connected status. Why is that happening?

        client.registerSession({ userId: "sarath", displayName: "dixit" });
        client.on("connectionStatusChanged", (data) => {
          console.log(data);
        });

Hi Sarath @sarathdixit,

Thanks for reaching out.

  1. ReactNat. can work with TS SDK without conflict, it is recommended you switch to TS SDK. So no doc for React is necessary nor in our plan yet so far.

  2. Please find code

  • can you please help share results from your console.log(data)?
  • once connected, can ignore this fx and continue with your operations
client.registerSession({ userId, displayName, authToken });
      client.on("connectionStatusChanged", ({ oldValue, newValue }) => {
        if (data == "connected") setConnected(true);
      });

Any other issues let us know, thanks.
Amity Support

As per your suggestion, I’m using typescript SDK but I’m getting error

Error: Amity SDK (400100): Invalid authentication token (0).

const client = createClient(
  API_KEY,
  API_REGIONS.SG
);
let isConnected = await connectClient({ userId: "testuser123" });

Hi @sarathdixit , from what’s sent it seems to be an issue with your auth token.

Were there some misnomer eg expired tokens (up to 10 min), etc (please refer here for details https://docs.amity.co/console/settings/security)?

@amitysupport I’ve initialized the SDK as per the above step you mentioned and disabled the secure mode but I’m getting the error

“Amity SDK (400100): Authorization info not found”

import {
  API_REGIONS,
  createClient,
  enableCache,
  connectClient,
  createQuery,
  createChannel,
  runQuery,
  createMessage,
} from "@amityco/ts-sdk";

const apiKey = API_KEY;

      const client = createClient(apiKey, API_REGIONS.SG);

      enableCache();

      const sessionHandler = {
        sessionWillRenewAccessToken(renewal) {
          renewal.renew();
        },
      };
      connectClient(
        { userId: "testuserID", displayName: "Bob Newton" },
        sessionHandler
      );
      const query = createQuery(createChannel, {
        displayName: "myChannel",
        tags: ["tag"],
        type: "standard",
        userIds: ["testuserID"],
        metadata: {
          data: "anything",
        },
      });

      runQuery(query, (result) => console.log(result));

@sarathdixit

  • can you try again but wait for connection status to change first? if it works
await connectClient({
      displayName: `${given_name} ${family_name}`,
      userId: sub,
    })
      .then(() => {
        console.log("connected");
        //create channel
      })
      .catch((e) => {
        console.log("error", e);
      });```

Hey @amitysupport finally SDK has connected thanks for the above solution. I created the conversation channel but that channel is not showing in the amity dashboard. I’ve shared the channel creation response below

Also, I have a few more questions

  1. How can I get all the channels related to the user?
  2. I have created a broadcast channel from the dashboard but I’m unable to join the channel.

Please provide me with a solution.

hi @sarathdixit noted, per these:

  1. query with criteria of filter:member or userID
    https://docs.amity.co/chat/channels/query-channels

  2. did mean in Amity Social Cloud Console dashboard?

These provide details that may help you create and access:

Hi @sarathdixit per your first question on convers. channel not showing on dashboard

That is actually by design - since conversations are private and not subjected to banword/allowedlist url they’re not shown on console/dashboard.

To see it you can just change it to ‘community type’ when creating channel

Amity Support

Thanks for the information.

1 Like

I’m trying to get all messages from the channel but it always throws me a validation error even though my channel id is correct.

“Amity SDK (500000): Parameters validation error!”

      const query = createQuery(queryMessages, {
        page: { limit: 5 },
        subChannelId: "8683general",
      });

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

Hi @sarathdixit may I confirm how did you generate channelID?

@sarathdixit also seems like you’re not using the channelID, that looks more like display name as channelId is a uuid and would be a different format.

Example: channelId: 632048646de41000d94f9151

@amitysupport I’ve created the channel id in the same format only it’s working now. But I’m facing a problem with observing messages without any refresh. I’m not seeing any example in the documentation.

Replied in this thread. :slight_smile: