2017-09-08 36 views
1

我想问一下如何正确使用缩略图卡片按钮。我希望按钮使用context.Wait(methodName)专门调用一个新方法。 现在我有缩略图卡按钮验证码:Thumb context Card.Wait()

thumbnailCard.Buttons = new[] {new CardAction(
         ActionTypes.MessageBack, $"Account", value: id 
         )}; 
var msg = context.MakeMessage(); 
msg.AttachmentLayout = AttachmentLayoutTypes.Carousel; 
msg.Attachments = cardAttachment.ToList(); 

await context.PostAsync(msg); 
context.Wait(methodName); **I want this to be called when button was clicked** 

但显然我不能开除每当我点击按钮的方法。 PS:我实际上是新的bot框架,所以任何帮助将不胜感激。谢谢。

注意:可能的重复不是我遇到的问题。我不是通过thumbnail.Buttons调用一个方法,而是我插入需要传递到另一个方法使用context.Wait(MethodName)的值,但我们有如何正确实现它的相同方法,但它不回答为什么我的问题无法启动我插入上下文的方法。等等。

+0

您必须将您想要调用的方法放在MessageReceived方法上,并检查您接收到的值(该值应与您在CardAction中传递的值相匹配) –

+0

可能的[如何调用特定回调函数点击Card Action - Bot Framework](https://stackoverflow.com/questions/40808192/how-to-call-a-specifc-callback-when-clicking-in-card-action-bot-framework) –

+0

@NicolasR我已经尝试过,但它没有在我的最终结果。 –

回答

0

感谢大家的回应。我通过使用ActionTypes.PostBack解决了问题,并没有使用MessageBackImBack

是的,我仍然使用Context.Wait(method)

0

你实际上是否需要使用context.Wait还是你正在尝试的?你可以使用它,但它会在按钮点击后等待消息,所以它看起来并不像你想要的那样。请回复,我可以调整我的答案,因为你真的需要它。

它看起来像你只是想在点击按钮后执行一个方法。为此,您可以使用以下代码并根据需要进行调整,这是我能想到的最简单的实现。请让我知道如果您有任何后续问题或需要别的东西:

private async Task MessageReceivedAsync(IDialogContext context, 
    IAwaitable<object> result) 
    { 
     var activity = await result as Activity; 
     var response = activity.CreateReply(); 

     IMessageActivity reply = context.MakeMessage(); 


     if (activity.Text.ToLowerInvariant() == "do stuff") 
     { 

      activity.CreateReply("I have done the stuff"); 
      await context.PostAsync(activity); 
     } 
     else 
     { 
      List<CardAction> cardButtons = new List<CardAction>(); 

      CardAction Button = new CardAction 
      { 
       Title = "do stuff", 
       //Type = ActionTypes.ImBack; //this will display "do stuff" in the chat window 
       Type = ActionTypes.PostBack, //same behavior except "do stuff" not displayed 
       Value = "do stuff" 
      }; 

      cardButtons.Add(Button); 

      HeroCard Card = new HeroCard() 
      { 
       Buttons = cardButtons 
      }; 
      Attachment plAttachment = Card.ToAttachment(); 

      reply.Attachments.Add(plAttachment); 

      await context.PostAsync(reply); 
     } 

     context.Wait(MessageReceivedAsync); 
    } 
+0

对不起,我迟到的回应。我已经通过使用回发来解决这个问题,而不是使用messagereceivedasync方法来检查我的富卡传递给我的值。谢谢。 –

+0

很高兴你得到它的工作 – JasonSowers