简体   繁体   English

如何通过 Rest API(传入 webhook)回复 Microsoft Teams 频道中的现有消息?

[英]How to reply to a existing message in Microsoft Teams channel via Rest API(incoming webhook)?

I am able to post a message to a team channel using incoming webhook(code sample below).我可以使用传入的 webhook(下面的代码示例)向团队频道发布消息。 What I am trying to achieve next is to reply to the same message whenever I have a new update.我接下来要实现的是每当我有新的更新时回复相同的消息。 It's just a simple message in reply and need not to be conversational bot.这只是一条简单的回复消息,不需要是对话机器人。 I tried searching and found some options like teams bot and microsoft graph api.我尝试搜索并找到了一些选项,例如团队机器人和微软图形 API。 I wanted to know if there is a straightforward way to do it using incoming webhook or something else before exploring this options.在探索这个选项之前,我想知道是否有一种直接的方法可以使用传入的 webhook 或其他东西来做到这一点。

import requests
import json
from urllib.request import Request, urlopen, URLError, HTTPError

webhookurl = "https://factset.webhook.office.com/webhookb2/******************"
message = {
            "@type": "MessageCard",
            "@context": "http://schema.org/extensions",
            "themeColor": "FF0000",
            "summary": "Event Happened",
            "sections": [
                {
                    "activityTitle": "Main Title",
                    "activitySubtitle": "Sub title",
                    "markdown": True,
                    "facts": [
                        {
                            "name": "Start Time (UTC)",
                            "value": "2021-06-11 05:48:10"
                        },
                        {
                            "name": "Last Updated Time (UTC)",
                            "value": "2021-06-11 06:16:15"
                        }
                    ] 
                },
        }

req = Request(webhookurl, data=json.dumps(message).encode("utf-8"),
                headers={"content-type": "application/json"})
try:
    response = urlopen(req)
    response.read()
except HTTPError as e:
    print("Request failed : ", e.code, e.reason)
except URLError as e:
    print("Server connection failed: ", e.reason, e.reason)

Currently Webhook doesn`t support to send back message.目前 Webhook 不支持发回消息。 This can be done by using Graph API .这可以通过使用Graph API来完成。 You can raise UserVoice if this needs to be considered as a future request.如果需要将其视为未来的请求,您可以提高UserVoice

I was able to do it via microsoft graph using delegated workflow.我能够使用委派的工作流程通过 microsoft graph 来做到这一点。 Get access on behalf of a user 代表用户获取访问权限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft Teams 传入 Webhook 按钮 \\w 文件链接 - Microsoft Teams Incoming Webhook Button \w File-Link 如何使用传入的 webhook API 在 MS 团队中创建公告 - How to create Announcement in MS teams using incoming webhook APIs Microsoft Teams:向用户发布直接消息以响应频道中的消息 - Microsoft Teams: Posting direct message to user in response to message in channel 如何回复我输入的频道之外的消息? - How do I reply to a message outside of the channel I typed in? 使用适用于 Python 的 Bot Framework SDK v4 初始化并向 Microsoft Teams 频道发送消息 - Initial and send a message to a Microsoft Teams channel using Bot Framework SDK v4 for Python 如何使用现有代码将 Python 中开发的聊天机器人集成到 Microsoft 团队 - how to integrate chatbot developed in Python to Microsoft teams using existing code 如何通过 Slack API 回复用户 DM? - How to reply to the user DM via Slack API? 如何通过Office 365 REST API检索Internet(消息)标头? - How to retrieve Internet (Message) Headers via Office 365 REST API? 如何通过它的 api 在 discord 通道中发送消息 - How to send message in discord channel by it's api 如何使用Slack API将格式化的消息发布到通道中 - How to post formatted message into a channel with Slack API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM