2017-09-08 34 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