2017-05-05 16 views
-1

私は数週間MSボットフレームワークを試してきましたが、うまくいきましたが、今日はこの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

は、Azureの上のあなたのボットですか?または、ローカルでテストしていますか?

この問題は、無効なMicrosoft App Id &アプリケーションパスワードが原因で発生します。それらが正しいこと、そしてあなたが 'https'を使用していることを確認してください。

+0

Azureにありますが、私はそれをローカルでテストしています。 IDとパスワードright – ryanez

+0

あなたのボトムはどうですか? –

+0

dev.botframework.comで新しいアプリを作成し、新しい値を使用してみてください。 Azureのデプロイメントが実際に動作していることを確認してください。変更を行うたびに、既存のファイルを削除するオプションを選択して、Web APIを再デプロイします。 これでうまくいかない場合は、ngrokを使用してローカルのbot Web APIを公開し、変更があるかどうかを確認します。 –

関連する問題