2016-07-25 5 views
2

파이썬 봇을 쓰고 싶습니다. 내 봇을 Microsoft 봇 커넥터에 연결할 수 있는지 알고 싶습니다.내 파이썬 봇을 Microsoft 봇 커넥터에 연결하는 방법

+1

Microsoft Bot Connector API에 연결하기 위해 작성한 라이브러리를 살펴볼 수 있습니다. 마이크로 소프트 팀을위한 봇을 쓸 때 정말 간단하지 않은 것을 찾을 수 없었습니다. https://github.com/Grungnie/microsoftbotframework –

답변

6

예 가능합니다. 구현을 위해 Microsoft bot built on Django (python web framework)을 확인하십시오.

여기 아래에 적절한 App IDApp secret<Microsoft App ID><Microsoft App Secret>를 교체하십시오 위의 예에서 마이크로 소프트 봇 커넥터

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"]) 
         } 
        ) 

에 회신하는 파이썬 코드입니다. 더 많은 API 체크 아웃은 Microsoft Bot Connector REST API - v3.0

+0

에뮬레이터에 연결하는 데 사용할 수 있다면 어떨까요? (외부 Microsoft 봇 프레임 워크가 아닙니다) – ShreyasG