2016-07-25 108 views
2

我想寫一個python機器人,我知道是否有可能將我的機器人連接到微軟機器人連接器?如何將我的python機器人連接到微軟機器人連接器

+1

您可以看看我一直在寫的連接到Microsoft Bot連接器API的庫。當我想爲微軟團隊編寫一個機器人時,我找不到任何真正簡單的東西,所以我創建了自己的機器人。 https://github.com/Grungnie/microsoftbotframework –

回答

6

是的,這是可能的。請檢查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 IDApp secret。 更多API結帳Microsoft Bot Connector REST API - v3.0

+0

任何想法,如果這可以用來連接到模擬器? (不是外部的微軟機器人框架) – ShreyasG