2017-05-05 1 views
-1

나는 MS 봇 프레임 워크를 2 주 동안 사용해 봤지만 훌륭하게 작동했지만 오늘은이 401 Unauthorized 오류가 발생했습니다.botframework 401 Unauthorized

MicrosoftAppId 및 MicrosoftAppPassword에 대한 빈 값을 설정하면 202 Accepted Code 및 JSON이 작동합니다.

{ 
    "type": "message", 
    "timestamp": "2017-05-05T19:16:05.9383241Z", 
    "serviceUrl": "http://localhost:9000/", 
    "channelId": "emulator", 
    "from": { 
    "id": "56800324", 
    "name": "Bot1" 
    }, 
    "conversation": { 
    "isGroup": false, 
    "id": "8a684db8", 
    "name": "Conv1" 
    }, 
    "recipient": { 
    "id": "2c1c7fa3", 
    "name": "User1" 
    }, 
    "text": "Has dicho: 55 tiene 2 caracteres. De momento no se hacer más.", 
    "attachments": [], 
    "entities": [], 
    "replyToId": "4e4621d62e544a99aa1ea385b12d536f" 
} 

내가 설정 MicrosoftAppId 및 MicrosoftAppPassword에 대한 값 (예, dev.botframework.com 그것을 몇 번을 확인 한 후 모두 맞다) 경우 작동하지 않습니다

401 Unathorized 
Connection: Keep-Alive 
Content-Length: 540 
Content-type: application/json ; charset=utf-8 
Host: Localhost:9000 
User-Agent: Microsoft.Bot.Connector.ConnectorClient/3.5.3.0 Microsoft-BotFramework/3.1 (BotBuilder .Net/3.5.3.0) 

및 JSON : 나는 dev.botframework.com에서 내 봇에 연결을 테스트하는 경우

{ 
    "type": "message", 
    "timestamp": "2017-05-05T19:19:15.4091892Z", 
    "serviceUrl": "http://localhost:9000/", 
    "channelId": "emulator", 
    "from": { 
    "id": "56800324", 
    "name": "Bot1" 
    }, 
    "conversation": { 
    "isGroup": false, 
    "id": "8a684db8", 
    "name": "Conv1" 
    }, 
    "recipient": { 
    "id": "2c1c7fa3", 
    "name": "User1" 
    }, 
    "text": "Has dicho: sdfs tiene 4 caracteres. De momento no se hacer más.", 
    "attachments": [], 
    "entities": [], 
    "replyToId": "0adec452277a489e9acc5b4403fa5965" 
} 

또한 무단 얻을.

아이디어가 있으십니까?
감사합니다.

UPDATE : 이 내 MessagesController 클래스입니다 :

namespace Geni.Controllers 
{ 
    [BotAuthentication] 
    public class MessagesController : ApiController 
    { 
     /// <summary> 
     /// POST: api/Messages 
     /// Receive a message from a user and reply to it 
     /// </summary> 
     public async Task<HttpResponseMessage> Post([FromBody]Activity activity) 
     { 
      if (activity.Type == ActivityTypes.Message) 
      { 
       ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); 
       // calculate something for us to return 
       int length = (activity.Text ?? string.Empty).Length; 

       // return our reply to the user 
       Activity reply = activity.CreateReply($"Has dicho: {activity.Text} tiene {length} caracteres. De momento no se hacer más."); 
       await connector.Conversations.ReplyToActivityAsync(reply); 
      } 
      else 
      { 
       HandleSystemMessage(activity); 
      } 
      var response = Request.CreateResponse(HttpStatusCode.OK); 
      return response; 

     } 
     private Activity HandleSystemMessage(Activity message) 
     { 
      if (message.Type == ActivityTypes.DeleteUserData) 
      { 
       // Implement user deletion here 
       // If we handle user deletion, return a real message 
      } 
      else if (message.Type == ActivityTypes.ConversationUpdate) 
      { 
       // Handle conversation state changes, like members being added and removed 
       // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info 
       // Not available in all channels 
      } 
      else if (message.Type == ActivityTypes.ContactRelationUpdate) 
      { 
       // Handle add/remove from contact lists 
       // Activity.From + Activity.Action represent what happened 
      } 
      else if (message.Type == ActivityTypes.Typing) 
      { 
       // Handle knowing tha the user is typing 
      } 
      else if (message.Type == ActivityTypes.Ping) 
      { 
      } 

      return null; 
     } 
    } 
} 
+0

일부 값이 잘못되었거나 ... 봇에 뭔가가 누락되었습니다. 귀하의 컨트롤러에 코드를 게시하십시오 –

답변

2

이 푸른에 봇인가? 아니면 로컬로 테스트 중입니까?

잘못된 Microsoft App Id & 응용 프로그램 암호로 인해 문제가 발생합니다. 올바른지, 'https'를 사용하고 있는지 확인하십시오.

+0

하늘에 있지만 로컬로 테스트하고 있습니다. Id and Password right – ryanez

+0

당신의 botid는 어떻습니까? –

+0

dev.botframework.com에 새 앱을 만들고 새로운 값을 사용하십시오. Azure에서 deploy가 실제로 작동하는지 확인하십시오. 변경할 때마다 기존 파일을 삭제하는 옵션을 선택하여 웹 API를 다시 배포합니다. 그래도 작동하지 않으면 ngrok를 사용하여 로컬 봇 웹 API를 노출하고 변경 사항이 있는지 확인하려고합니다. –

관련 문제