在频道机器人中发送通知

Sending notifications in the channel bot

我目前正处于将我的应用程序批准进入商店的审批过程中。剩下的问题之一是:

1. Employer and Employee both didn’t receive any notification in the channel bot

我的聊天机器人目前在 manifest.json 中设置为 notificationOnly,因为我不 need/want 用户直接向它发送消息。

查看 "Proactive Messaging" 文档,关于什么消息以及何时发送它们会通过上述故障有点模糊。

我需要将消息发送到频道吗?

我目前正在使用 NodeJS

谢谢

这是一个涵盖很多领域的长答案,只是因为我不能 100% 确定我知道您没有收到哪种通知。如果这不能回答问题,请在您的问题中添加更多详细信息,我将编辑此答案。

疑难解答

  • Troubleshooting Guide
    • 特别注意需要启用通知的许多区域
      • 特别是,用户可能需要"Follow"and/or"Favorite"接收通知的频道
  • 如果用户打开了桌面应用程序,他们将在那里收到通知,并且不会在 phone 上收到通知,除非他们在桌面应用程序上处于非活动状态超过 3 分钟。否则,这可能是 Teams 中的错误。

聊天通知

如果您按照上面链接的故障排除指南进行操作,您的用户应该会收到聊天通知。如果没有,您可以尝试更新您的 MS Teams 桌面或移动客户端。 @ 提及用户 and/or 频道

也可能会有帮助

发送 Activity 正常通知

通常,需要从下面添加 trustServiceUrl 代码的关键问题。通常,忽略执行此操作会出现 500 错误,但对于 Teams,它似乎不会创建通知。您基本上需要设置 turncontext.activity 的几个属性并信任 serviceUrl.

实例化一些关键变量:

const teamsChannel = '19:8d60061c3d10xxxxxxxxxxxxxxxx@thread.skype';
const serviceUrl = 'https://smba.trafficmanager.net/amer/';
  • 注意:获取这些变量的最简单方法是从 Teams 向机器人发送消息,同时在传入 activity
  • 上放置断点
  • serviceUrl 可能因地理区域而异

发送activity

// This ensures that your bot can send to Teams - serviceUrl ensures notifications, too
turnContext.activity.conversation.id = teamsChannel;
turnContext.activity.serviceUrl = serviceUrl;
MicrosoftAppCredentials.trustServiceUrl(serviceUrl);

await turnContext.sendActivity(yourActivity);

Activity 订阅源通知

你也可以create Activity Feed Notifications。它的要点是你需要:

  1. 在消息中包含 textsummary
  2. 包括将 notifications.alert 设置为 true
  3. channelData

这段代码将完成:

const msg = MessageFactory.text('my message');
msg.summary = 'my summary';
msg.channelData = {
    notification: {
        alert: true,
    },
};
return await dc.context.sendActivity(msg);

结果:

注意:要接收通知,您和您的用户必须关注频道。