2016-07-28 17 views
0

Hallo Ich entwickle einen Bot mit Microsoft botframework Projekt in dem ich IDialog Schnittstelle verwende. In diesem verwende ich die ThumbnailCard für die Anzeige der Karten. Hier, wenn ich einige Daten an meine Karten anschließe und die Daten richtig anhängen, aber innerhalb der PostAsync Methode liefert es nicht die Antwort.Wie benutze ich die ThumbnailCard in IDialog Kontext

public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument) 
    { 
     ThumbnailCard plCard = null; 
     IMessageActivity replyToConversation =await argument; 
     replyToConversation.Type = "message"; 
     replyToConversation.Attachments = new List<Attachment>(); 
     replyToConversation.Text = "welcome to book my show"; 
     Dictionary<string, string> cardContentList = new Dictionary<string, string>(); 
     cardContentList.Add("Jason Bourne", "URL"); 
     cardContentList.Add("The Land", "URL"); 
     cardContentList.Add("Yoga Hosers", "URL"); 
     foreach (KeyValuePair<string, string> cardContent in cardContentList) 
     { 
      List<CardImage> cardImages = new List<CardImage>(); 
      cardImages.Add(new CardImage(url: cardContent.Value)); 
      List<CardAction> cardButtons = new List<CardAction>(); 
      if (cardContent.Key == "Jason Bourne") 
      { 
       CardAction plButton1 = new CardAction() 
       { 
        Value = $"", 
        Type = "openUrl", 
        Title = "Book Now" 
       }; 

       CardAction plButton2 = new CardAction() 
       { 
        Value = "tel:1-800-800-5705", 
        Type = "call", 
        Title = "Show timings" 
       }; 
       cardButtons.Add(plButton1); 
       cardButtons.Add(plButton2); 

       plCard = new ThumbnailCard() 
       { 
        Title = $"Jason Bourne", 
        Subtitle = " ", 
        Images = cardImages, 
        Buttons = cardButtons, 

       }; 
       Attachment plAttachment = plCard.ToAttachment(); 
       replyToConversation.Attachments.Add(plAttachment); 
      } 
      else if (cardContent.Key == "The Land") 
      { 
       CardAction plButton1 = new CardAction() 
       { 
        Value = $"", 
        Type = "openUrl", 
        Title = "Book Now" 
       }; 
       CardAction plButton2 = new CardAction() 
       { 
        Value = "tel:1-800-800-5705", 
        Type = "call", 
        Title = "Show Timings" 
       }; 
       cardButtons.Add(plButton1); 
       cardButtons.Add(plButton2); 

       plCard = new ThumbnailCard() 
       { 
        Title = $"The Land", 
        Subtitle = "", 
        Images = cardImages, 
        Buttons = cardButtons, 

       }; 
       Attachment plAttachment = plCard.ToAttachment(); 
       replyToConversation.Attachments.Add(plAttachment); 
      } 
      else if (cardContent.Key == "Yoga Hosers") 
      { 

       CardAction plButton1 = new CardAction() 
       { 
        Value = $"", 
        Type = "openUrl", 
        Title = "Book Now" 
       }; 
       CardAction plButton2 = new CardAction() 
       { 
        Value = "tel:1-800-800-5705", 
        Type = "call", 
        Title = "Show timings" 
       }; 
       cardButtons.Add(plButton1); 
       cardButtons.Add(plButton2); 

       plCard = new ThumbnailCard() 
       { 
        Title = $"Yoga Hosers", 
        Subtitle = "", 
        Images = cardImages, 
        Buttons = cardButtons, 
       }; 
       Attachment plAttachment = plCard.ToAttachment(); 
       replyToConversation.Attachments.Add(plAttachment); 
      } 
     } 
     replyToConversation.AttachmentLayout = AttachmentLayoutTypes.List; 
     await context.PostAsync(replyToConversation); 
    }  

Als ich den Bot seine Show der folgende Fehler enter image description here

laufen Können wir Karten in iDialog Kontext für Anlagen verwenden?

Antwort

1

Das Problem ist mit der IMessageActivity, versuchen Sie IMessageActicity in context.PostAsync zu senden. Das ist der Grund, warum es versagt.

die folgenden Änderungen durchführen, um es

Ändern Sie die Methodensignatur wie unter

private async Task messageReceived(IDialogContext context, IAwaitable<object> argument) 

und ändern die IMessageActivity replyToConversation =await argument; mögen unter

var message = await argument as Activity;   
     Activity replyToConversation = message.CreateReply("Welcome." + "(Hi)"); 
     replyToConversation.Recipient = message.From; 

Jetzt sollte es funktionieren arbeiten machen, wenn Sie habe noch ein Problem, bitte hier kommentieren.

-Kishore

+0

Vielen Dank Kishore und vielen Dank für Ihren Vorschlag und jetzt funktioniert mein Code richtig – sateesh