在 Twilio 中发送聊天消息时,在另一个浏览器中收到通知



我使用以下代码使用 Twilio 发送消息:

string channelId = <channelId>;
string serviceSid = <servicesid>;
IpMessagingClient ipMessagingClient = new IpMessagingClient(<accountid>, <token>);
var msgResult = ipMessagingClient.CreateMessage(serviceSid, channelId, "sender", "message");
msg.Body = "body"
msg.DateSent = DateTime.Now;
msg.Sender = "sender"
return Json(new
{
    Success = msgResult.Sid != null,
    NewMessage = msg
});

消息发送得很好,我可以检索频道的消息。我现在要实现的是其他打开的浏览器,并在频道中收到发送的新消息的通知,以便我可以更新 UI 以显示新消息,而无需手动刷新浏览器。

Twilio开发者布道者在这里。

看起来您正在使用 REST API 向可编程聊天 API 发送消息。

为了使用客户端版本,特别是JS客户端,我将通读可编程聊天文档,下载JS SDK并查看参考聊天演示的代码。所有这些位都应该为客户端构建聊天奠定良好的基础。

让我知道这是否有帮助。

相关内容

最新更新