如何将我的python机器人连接到微软机器人连接器
答
是的,这是可能的。请检查Microsoft bot built on Django (python web framework)执行。这里下面
是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"])
}
)
在上面的示例请更换<Microsoft App ID>
和<Microsoft App Secret>
适当App ID
和App secret
。 更多API结帐Microsoft Bot Connector REST API - v3.0
+0
任何想法,如果这可以用来连接到模拟器? (不是外部的微软机器人框架) – ShreyasG
您可以看看我一直在写的连接到Microsoft Bot连接器API的库。当我想为微软团队编写一个机器人时,我找不到任何真正简单的东西,所以我创建了自己的机器人。 https://github.com/Grungnie/microsoftbotframework –