在渠道机器人中发送通知

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

我目前正在批准将我的应用程序批准进入商店。其余问题之一是:

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

我的机器人目前在manifest.json中设置为notificationOnly,因为我不需要/希望用户直接发送消息。

通过“主动消息传递”文档,对于哪些消息以及何时发送它们会通过上述故障,它有点模糊。

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

我目前正在使用NodeJS

谢谢

node.js botframework microsoft-teams
1个回答
0
投票

这是一个很长的答案,涵盖了很多领域,仅仅因为我不是100%确定我知道你没有收到什么样的通知。如果没有回复,请在您的问题中添加其他详细信息,我将编辑此答案。

Troubleshooting

  • Troubleshooting Guide 请特别注意需要启用通知的许多区域 特别地,用户可能需要“跟随”和/或“收藏”频道以从其接收通知
  • 如果用户打开桌面应用程序,他们将在那里收到通知,除非他们在桌面应用程序上处于非活动状态3分钟以上,否则他们将不会在手机上收到通知。否则,它可能是团队中的一个错误。

Chat Notifications

如果您已按照上面链接的“问题排查指南”进行操作,则您的用户应接收聊天通知如果没有,您可以尝试更新MS Teams桌面或移动客户端。 @提及用户和/或频道也许会有所帮助

Sending an Activity With a Normal Notification

通常,需要从下面添加trustServiceUrl代码的关键问题。通常,忽略这样做会表现为500错误,但对于团队而言,似乎不会创建通知。您基本上需要设置turncontext.activity的几个属性并信任serviceUrl。

实例化一些关键变量:

const teamsChannel = '19:[email protected]';
const serviceUrl = 'https://smba.trafficmanager.net/amer/';
  • 注意:获取这些变量的最简单方法是将来自团队的消息发送到机器人,同时在传入活动上设置断点
  • serviceUrl可能因地理区域而异

发送活动

// 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 Feed Notifications

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

  1. 在邮件中包含textsummary
  2. 包括将channelData设置为true的notifications.alert

这段代码将实现:

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

结果:

enter image description here enter image description here

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

© www.soinside.com 2019 - 2024. All rights reserved.