2017-05-05 5 views
-1

Ich habe MS Bot Framework für ein paar Wochen versucht und es hat gut funktioniert, aber heute habe ich diese 401 nicht autorisierten Fehler.Botframework 401 Nicht autorisierte

Wenn ich leere Werte für MicrosoftAppId und MicrosoftAppPassword aufstelle, funktioniert es, einen 202 akzeptierten Code und JSON zu erhalten.

{ 
    "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" 
} 

Wenn ich Setup ein Wert für MicrosoftAppId und MicrosoftAppPassword (ja, ich habe es mehrmals an dev.botframework.com geprüft und beide dann sind rechts), dann funktioniert es nicht:

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) 

und JSON:

{ 
    "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" 
} 

Wenn ich Verbindung zu meinem bot-Test bei dev.botframework.com ich auch Unberechtigte.

Irgendwelche Ideen?
Danke!

UPDATE: Das ist mein MessagesController Klasse:

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

Einige der Werte müssen falsch sein ... oder Ihr Bot fehlt etwas. posten Sie bitte den Code in Ihrem Controller –

Antwort

2

Ist Ihr Bot auf Azure? Oder testen Sie es lokal?

Das Problem tritt aufgrund ungültiger Microsoft App-ID & App-Kennwort auf. Stellen Sie sicher, dass diese korrekt sind und Sie "https" verwenden.

+0

Ist auf Azure, aber ich teste es lokal. Id und Passwort rechts – ryanez

+0

Was ist mit Ihrem Botid? –

+0

Versuchen Sie, eine neue App auf dev.botframework.com zu erstellen, und verwenden Sie ihre neuen Werte. Stellen Sie sicher, dass die Bereitstellung in Azure tatsächlich funktioniert. Jedes Mal, wenn Sie eine Änderung vornehmen, wählen Sie die Option zum Löschen bereits vorhandener Dateien aus, damit Ihre Web-API erneut implementiert wird. Wenn das nicht funktioniert, würde ich versuchen, ngrok verwenden, um Ihre lokale Bot Web API zu offenbaren, und sehen, ob sich etwas ändert. –

Verwandte Themen