我@aws-sdk/client-chime-sdk-messaging
用来发出获取/发送/删除频道消息的请求
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);
}
问题:如何接收消息,或订阅事件监听器来处理收到的消息。
我曾经用and而不是amazon-chime-sdk-js
来做这部分,它的工作原理是这样的:aws-sdk/clients/chime
aws-sdk
@aws-sdk/client-chime-sdk-messaging
const sessionConfig = new MessagingSessionConfiguration(
memberArm,
null,
endpoint,
chime,
AWS
);
this._session = new DefaultMessagingSession(sessionConfig, this._logger);
this._session.addObserver(this.messageObserver);
this._session.start();
而且我正在尝试减少 aws-sdk 库的大小,我认为使用新的 was-sdk-js-v3 客户端应该与以前的版本不同。
我用于聊天连接的连接示例来自amazon-chime-sdk-js