使用/sendActivityNotification API发送的Teams活动通知在移动端不显示
我开发的Microsoft Teams应用通过/sendActivityNotification API向团队内用户发送活动通知,该通知在网页版和桌面版正常显示,但Android、iOS移动端完全无法接收——通知栏始终为空,也未收到推送通知。已严格遵循Microsoft官方活动通知文档编写发送逻辑,认证环节按要求申请了TeamsActivity.Send.User权限,文档未提及移动端适配的额外步骤。
后端发送通知的示例代码如下:
let activityParams = { topic: { source: 'text', value: 'Zervise', webUrl: getDeepLink( existingCompany.msteams.entityId, existingCompany.msteams.orgId, existingCompany.msteams.teamId, existingCompany.msteams.channelId ), }, activityType: 'waitingForApproval', previewText: { content: `Ticket #${ticketAfterUpdate.ticketNumber} is waiting for your approval.`, }, recipient: { "@odata.type": "microsoft.graph.aadUserNotificationRecipient", "userId": `${recipientMsTeamsId}` }, templateParameters: [ { name: 'ticketNumber', value: `${ticketAfterUpdate.ticketNumber}`, }, ], }; const { data, status } = await axios({ method: 'POST', url: `https://graph.microsoft.com/v1.0/teams/${existingCompany.msteams.teamId}/sendActivityNotification`, headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json', }, data: activityParams, }); if (status != 204 && status != 200) throw new Error('could not send activity notification');
以下是针对性排查建议:
检查移动端Teams通知权限
确认用户移动端Teams应用已开启完整通知权限:iOS进入「设置」→「Teams」→「通知」,确保允许通知并开启所有通知样式;Android进入应用设置→「通知」,开启横幅、声音、锁屏通知等权限。验证activityType的注册一致性
活动通知的activityType必须在Teams应用manifest的activityTypes字段中提前注册,且发送时的activityType与manifest中的值完全一致(包括大小写、拼写)。检查manifest配置是否包含waitingForApproval。切换recipient类型测试
尝试将recipient从aadUserNotificationRecipient改为conversationMemberNotificationRecipient(使用用户在目标团队内的成员ID),排查是否存在用户ID匹配问题。同时确认用户是目标团队的有效成员,未被移除或退出。校验webUrl的DeepLink格式
移动端对Teams DeepLink的格式要求更严格,验证getDeepLink生成的URL是否符合官方规范,直接在移动端Teams中打开该链接,确认能正常跳转到目标页面。获取Graph API详细返回信息
在请求中添加Prefer: return=representation请求头,即使返回204状态码,也能获取更详细的响应内容,排查是否存在移动端特有的隐性错误。更新移动端Teams版本
建议用户将Teams更新到最新版本,旧版本可能存在API兼容性问题,部分活动通知特性仅在新版本中支持。
内容的提问来源于stack exchange,提问作者Soumya Dey

