0

I'm using @aws-sdk/client-chime-sdk-messaging to make requests to get/send/delete channel messages

import { ChimeSDKMessagingClient, ListChannelMessagesCommand } from "@aws-sdk/client-chime-sdk-messaging";

const credentials = {
    accessKeyId: "accessKeyId",
    secretAccessKey: "secretAccessKey",
    sessionToken: "sessionToken"
};

const ChannelArn = "arn:aws:chime:us-east-1:ChannelArn";

const userArn = "arn:aws:chime:us-east-1:userArn";

const chimeClient = new ChimeSDKMessagingClient({
    region: "us-east-1",
    credentials
});

const params = {
    ChannelArn,
    MaxResults: 50,
    NextToken: null,
    ChimeBearer: userArn
};

const command = new ListChannelMessagesCommand(params);

try {
    const data = await chimeClient.send(command);
    console.log("listChannelMessages DATA ->", data);
} catch (error) {
    console.error("listChannelMessages ERROR ->", error);
}

Question: How can I receive messages, or subscribe with event listener to process received messages.

I've used amazon-chime-sdk-js to do this part with aws-sdk/clients/chime and aws-sdk instead of @aws-sdk/client-chime-sdk-messaging and it worked like that:

const sessionConfig = new MessagingSessionConfiguration(
  memberArm,
  null,
  endpoint,
  chime,
  AWS
);

this._session = new DefaultMessagingSession(sessionConfig, this._logger);

this._session.addObserver(this.messageObserver);
this._session.start();

And I'm trying to reduce the aws-sdk libs size and I think with new was-sdk-js-v3 clients it should work differently from the previous version.

The connect example I've used for my chat connection is from amazon-chime-sdk-js

Alisa Liso
  • 36
  • 7

1 Answers1

0

In the meantime, the examples provided on github contain the updated libraries for V3.

So you could update your code you have to make use of that, as indicated on here (https://github.com/aws/amazon-chime-sdk-js#messaging-session):

import { ChimeSDKMessagingClient, GetMessagingSessionEndpointCommand } from '@aws-sdk/client-chime-sdk-messaging';

import {
  ConsoleLogger,
  DefaultMessagingSession,
  LogLevel,
  MessagingSessionConfiguration,
} from 'amazon-chime-sdk-js';

const logger = new ConsoleLogger('SDK', LogLevel.INFO);

// You will need AWS credentials configured before calling AWS or Amazon Chime APIs.
const chime = new ChimeSDKMessagingClient({ region: 'us-east-1'});
const endpoint = await chime.send(new GetMessagingSessionEndpointCommand());

const userArn = /* The userArn */;
const sessionId = /* The sessionId */;
const configuration = new MessagingSessionConfiguration(userArn, sessionId, endpoint.Endpoint.Url, chime);
const messagingSession = new DefaultMessagingSession(configuration, logger);