【问题标题】:How to connect my python bot to microsoft bot connector如何将我的 python bot 连接到 microsoft bot 连接器
【发布时间】:2017-05-03 22:06:57
【问题描述】:

我想写一个 python bot,我知道是否可以将我的 bot 连接到 microsoft bot 连接器?

【问题讨论】:

  • 您可以查看我一直在编写的用于连接到 Microsoft Bot 连接器 API 的库。当我想为 Microsoft Teams 编写一个机器人时,我找不到任何真正简单的东西,所以我自己开始了。 github.com/Grungnie/microsoftbotframework

标签: python bots botconnector


【解决方案1】:

是的,这是可能的。请查看Microsoft bot built on Django (python web framework) 进行实施。

下面是回复 Microsoft bot 连接器的 python 代码

import requests
app_client_id = `<Microsoft App ID>`
app_client_secret = `<Microsoft App Secret>`
def sendMessage(serviceUrl,channelId,replyToId,fromData, recipientData,message,messageType,conversation):
    url="https://login.microsoftonline.com/common/oauth2/v2.0/token"
    data = {"grant_type":"client_credentials",
        "client_id":app_client_id,
        "client_secret":app_client_secret,
        "scope":"https://graph.microsoft.com/.default"
       }
    response = requests.post(url,data)
    resData = response.json()
    responseURL = serviceUrl + "v3/conversations/%s/activities/%s" % (conversation["id"],replyToId)
    chatresponse = requests.post(
                       responseURL,
                       json={
                        "type": messageType,
                        "timestamp": datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f%zZ"),
                        "from": fromData,
                        "conversation": conversation,
                        "recipient": recipientData,
                        "text": message,
                        "replyToId": replyToId
                       },
                       headers={
                           "Authorization":"%s %s" % (resData["token_type"],resData["access_token"])
                       }
                    )

在上面的示例中,请将&lt;Microsoft App ID&gt;&lt;Microsoft App Secret&gt; 替换为适当的App IDApp secret。 更多 API 结帐Microsoft Bot Connector REST API - v3.0

【讨论】:

  • 知道这是否可以用来连接模拟器吗? (不是外部 microsoft bot 框架)
猜你喜欢
  • 1970-01-01
  • 2018-05-22
  • 2017-11-01
  • 2021-06-27
  • 1970-01-01
  • 2021-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多