2016-10-19 4 views
0

Ich bin mit Microsofts Bot Framework und ihre Tutorial folgenden (C# für die .NET-Version verwenden) auf den Aufbau eines Simple Sandwich BotMS Bot Framework-Sandwich Bot JSON auf Befehl zeigt Linie

ich es geschafft haben, die einfache Version des bekommen Bot funktioniert jedoch, wenn ich mit dem Bot auf einer der Stufen des Typs enum interagieren, wird die Antwort vom Bot im JSON-Format angezeigt (im Gegensatz zu dem einfachen Englisch, das das Beispiel zeigt) - kann mir jemand weiterhelfen dieses? Ich verwende die Befehlszeilenversion des Emulators, da der ClickOnce-Emulator Probleme mit der Proxyauthentifizierung in dem Netzwerk hat, in dem ich bin.

Ich bin mit dem Standard-Code auf der Website zur Verfügung gestellt: -

Sandwich.cs:

using Microsoft.Bot.Builder.FormFlow; 
using System; 
using System.Collections.Generic; 
#pragma warning disable 649 
// The SandwichOrder is the simple form you want to fill out. It must be serializable so the bot can be stateless. 
// The order of fields defines the default order in which questions will be asked. 
// Enumerations shows the legal options for each field in the SandwichOrder and the order is the order values will be presented 
// in a conversation. 
namespace Microsoft.Bot.Sample.SimpleSandwichBot 
{ 
    public enum SandwichOptions 
    { 
     BLT, BlackForestHam, BuffaloChicken, ChickenAndBaconRanchMelt, ColdCutCombo, MeatballMarinara, 
     OvenRoastedChicken, RoastBeef, RotisserieStyleChicken, SpicyItalian, SteakAndCheese, SweetOnionTeriyaki, Tuna, 
     TurkeyBreast, Veggie 
    }; 
    public enum LengthOptions { SixInch, FootLong }; 
    public enum BreadOptions { NineGrainWheat, NineGrainHoneyOat, Italian, ItalianHerbsAndCheese, Flatbread }; 
    public enum CheeseOptions { American, MontereyCheddar, Pepperjack }; 
    public enum ToppingOptions 
    { 
     Avocado, BananaPeppers, Cucumbers, GreenBellPeppers, Jalapenos, 
     Lettuce, Olives, Pickles, RedOnion, Spinach, Tomatoes 
    }; 
    public enum SauceOptions 
    { 
     ChipotleSouthwest, HoneyMustard, LightMayonnaise, RegularMayonnaise, 
     Mustard, Oil, Pepper, Ranch, SweetOnion, Vinegar 
    }; 
    [Serializable] 
    public class SandwichOrder 
    { 
     public SandwichOptions? Sandwich; 
     public LengthOptions? Length; 
     public BreadOptions? Bread; 
     public CheeseOptions? Cheese; 
     public List<ToppingOptions> Toppings; 
     public List<SauceOptions> Sauce; 
     public static IForm<SandwichOrder> BuildForm() 
     { 
      return new FormBuilder<SandwichOrder>() 
        .Message("Welcome to the simple sandwich order bot!") 
        .Build(); 
     } 
    }; 
} 

MessageController.cs:

using System; 
using System.Diagnostics; 
using System.Linq; 
using System.Net; 
using System.Net.Http; 
using System.Threading.Tasks; 
using System.Web.Http; 
using System.Web.Http.Description; 
using Microsoft.Bot.Builder.Dialogs; 
using Microsoft.Bot.Builder.FormFlow; 
using Microsoft.Bot.Connector; 
using Newtonsoft.Json; 

namespace ProperBot 
{ 
    [BotAuthentication] 
    public class MessagesController : ApiController 
    { 
     /// <summary> 
     /// POST: api/Messages 
     /// Receive a message from a user and reply to it 
     /// </summary> 
     internal static IDialog<SandwichOrder> MakeRootDialog() 
     { 
      return Chain.From(() => FormDialog.FromForm(SandwichOrder.BuildForm)) 
       .Do(async (context, order) => 
       { 
        try 
        { 
         var completed = await order; 
         // Actually process the sandwich order... 
         await context.PostAsync("Processed your order!"); 
        } 
        catch (FormCanceledException<SandwichOrder> e) 
        { 
         string reply; 
         if (e.InnerException == null) 
         { 
          reply = $"You quit on {e.Last}--maybe you can finish next time!"; 
         } 
         else 
         { 
          reply = "Sorry, I've had a short circuit. Please try again."; 
         } 
         await context.PostAsync(reply); 
        } 
       }); 
     } 
     [ResponseType(typeof(void))] 
     public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity) 
     { 

      if (activity != null) 
      { 
       // one of these will have an interface and process it 
       switch (activity.GetActivityType()) 
       { 
        case ActivityTypes.Message: 
         await Conversation.SendAsync(activity, MakeRootDialog); 
         break; 
        case ActivityTypes.ConversationUpdate: 
        case ActivityTypes.ContactRelationUpdate:   
        case ActivityTypes.Typing:   
        case ActivityTypes.DeleteUserData:    
        default: 
         Trace.TraceError($"Unknown activity type ignored: {activity.GetActivityType()}"); 
         break; 
       } 

      } 
      var response = Request.CreateResponse(HttpStatusCode.OK); 
      return response; 
     } 

    } 
} 

Die Antwort, die ich erhalte:

Bot1 said: 
Welcome to the sandwich order bot! 
Bot1 said: 

[ 
    { 
    "contentType": "application/vnd.microsoft.card.hero", 
    "content": { 
     "text": "What kind of sandwich would you like, eh? ", 
     "buttons": [ 
     { 
      "type": "imBack", 
      "title": "BLT", 
      "value": "BLT" 
     }, 
     { 
      "type": "imBack", 
      "title": "Black Forest Ham", 
      "value": "Black Forest Ham" 
     }, 
     { 
      "type": "imBack", 
      "title": "Buffalo Chicken", 
      "value": "Buffalo Chicken" 
     }, 
     { 
      "type": "imBack", 
      "title": "Chicken And Bacon Ranch Melt", 
      "value": "Chicken And Bacon Ranch Melt" 
     }, 
     { 
      "type": "imBack", 
      "title": "Cold Cut Combo", 
      "value": "Cold Cut Combo" 
     }, 
     { 
      "type": "imBack", 
      "title": "Meatball Marinara", 
      "value": "Meatball Marinara" 
     }, 
     { 
      "type": "imBack", 
      "title": "Oven Roasted Chicken", 
      "value": "Oven Roasted Chicken" 
     }, 
     { 
      "type": "imBack", 
      "title": "Roast Beef", 
      "value": "Roast Beef" 
     }, 
     { 
      "type": "imBack", 
      "title": "Rotisserie Style Chicken", 
      "value": "Rotisserie Style Chicken" 
     }, 
     { 
      "type": "imBack", 
      "title": "Spicy Italian", 
      "value": "Spicy Italian" 
     }, 
     { 
      "type": "imBack", 
      "title": "Steak And Cheese", 
      "value": "Steak And Cheese" 
     }, 
     { 
      "type": "imBack", 
      "title": "Sweet Onion Teriyaki", 
      "value": "Sweet Onion Teriyaki" 
     }, 
     { 
      "type": "imBack", 
      "title": "Tuna", 
      "value": "Tuna" 
     }, 
     { 
      "type": "imBack", 
      "title": "Turkey Breast", 
      "value": "Turkey Breast" 
     }, 
     { 
      "type": "imBack", 
      "title": "Veggie", 
      "value": "Veggie" 
     } 
     ] 
    } 
    } 
] 

Die Antwort, die ich empfangen werden sollen:

Please select a sandwich 
1. BLT 
2. Black Forest Ham 
3. Buffalo Chicken 
4. Chicken And Bacon Ranch Melt 
5. Cold Cut Combo 
6. Meatball Marinara 
7. Oven Roasted Chicken 
8. Roast Beef 
9. Rotisserie Style Chicken 
10. Spicy Italian 
11. Steak And Cheese 
12. Sweet Onion Teriyaki 
13. Tuna 
14. Turkey Breast 
15. Veggie 
> 

Bitte beachten Sie, dass ich nur diese Art von Antwort erhalten, wenn der Bot mit einem enum beschäftigt - wenn der Bot mit einem List Typ oder string tun haben, dann werden die Antworten sind in reinem Englisch.

+1

sieht eher wie ein Fehler aus, der bei Github abgelegt werden sollte, obwohl die klugen, gelehrten Männer vom MS-Bot-Framework-Team auch beim Stackoverflow lauern. – K48

Antwort

0

Es ist, weil die Konsole diese Arten von Antworten nicht lesen kann, da sie eine Antwort vom Microsoft-Typ sind, die "Karten" genannt wird - Anwendungen wie Skype, Facebook Messenger und E-mail können es lesen.

Verwandte Themen