.netstream.io chat API-频道不包括响应中的消息 我目前正在尝试在.NET Stream.io Chat API中使用channelclient。我成功地通过ID获取了我的频道,但是它并不包括我认为应该的信息。为什么这不是

问题描述 投票:0回答:0

创建

Channel
ChannelClient
通过频道ID来检索我的频道(也希望也希望也希望消息):

private static IChannelClient ChannelClient { get { var config = ServiceLocator.GetService<IConfigUtility>(); var clientFactory = new StreamClientFactory(config.ApiKey, config.ApiSecret); return clientFactory.GetChannelClient(); } }

最后,来自stream.io聊天API资源管理器的屏幕截图显示给定的频道存在并包含消息。

    

默认值,
ChannelClient

不包括频道状态(例如消息)。您需要通过在ChannelgetRequest中设置“状态= true”来明确要求它。

public async Task<ChatMessageDto[]> GetChannelMessages(string channelId) { try { var channel = await ChannelClient.GetOrCreateAsync("messaging", //channel id is: 4a20bbb1-63f9-46f7-80d3-08dd51a1dfad channelId, new ChannelGetRequest { MessagesPagination = new MessagePaginationParams { Limit = 50, Offset = 0 }, MembersPagination = new PaginationParams { Limit = 10, Offset = 0 }, WatchersPagination = new PaginationParams { Limit = 20, Offset = 0 } }); return channel.Messages.Select(x => new ChatMessageDto //channel.Messages is always empty here { StreamMessageId = x.Id, CreatedBy = x.User.Id, CreatedDate = x.CreatedAt, MessageText = x.Text, ChannelId = channel.Channel.Id }).ToArray(); } catch (Exception ex) { Logger.LogError(ex, $"Failed to get messages for channel id: {channelId} at {DateTimeOffset.UtcNow}"); return []; } }

enter image description here

c# asp.net-core .net-core chat getstream-io
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.