2017-05-16 1 views
3

NodeJSでAdaptiveCards npmパッケージを使用してプログラムでカードを生成しようとしていますが、メッセージに渡すJSONの生成方法がわかりません。これまでのところ、私のコードは非常に簡単です:AdaptiveCard:Node.jsでの使用方法

session.send(new builder.Message(session).addAttachment({ 
    contentType: "application/vnd.microsoft.card.adaptive", 
    content: createCard() 
})); 

function createCard() { 
    let card = new adaptiveCards.AdaptiveCard({ type: "AdaptiveCard" }); 

    // add a text block 
    card.addItem(new adaptiveCards.TextBlock({ 
     text: 'Issue #1', 
     weight: "bolder", 
     size: "medium" 
    })); 

    return card; 
} 

私はrenderメソッドの呼び出しを試みたが、それは動作しませんでした。私もJSON.stringify(card)に電話しようとしましたが、TypeError: Converting circular structure to JSONというメッセージが表示されます。 JSONをコンテンツの添付ファイルに渡すと、すべて正常に動作します。

答えて

5

Node.js用のBot Framework SDKを使用してAdaptive Cardを送信するには、Adaptivecards.ioで記述されているJSON形式を使用し、botbuilder.Messageオブジェクトにアダプティブカードオブジェクトを追加してから通常通りメッセージを送信します。

例:

// adaptive cards example from: 
// https://docs.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-send-rich-cards 
bot.dialog('adaptive_card_demo', function(session) { 
    var adaptiveCardMessage = new builder.Message(session) 
    .addAttachment({ 
     contentType: "application/vnd.microsoft.card.adaptive", 
     content: { 
      type: "AdaptiveCard", 
      speak: "<s>Your meeting about \"Adaptive Card design session\"<break strength='weak'/> is starting at 12:30pm</s><s>Do you want to snooze <break strength='weak'/> or do you want to send a late notification to the attendees?</s>", 
       body: [ 
        { 
         "type": "TextBlock", 
         "text": "Adaptive Card design session", 
         "size": "large", 
         "weight": "bolder" 
        }, 
        { 
         "type": "TextBlock", 
         "text": "Conf Room 112/3377 (10)" 
        }, 
        { 
         "type": "TextBlock", 
         "text": "12:30 PM - 1:30 PM" 
        }, 
        { 
         "type": "TextBlock", 
         "text": "Snooze for" 
        }, 
        { 
         "type": "Input.ChoiceSet", 
         "id": "snooze", 
         "style":"compact", 
         "choices": [ 
          { 
           "title": "5 minutes", 
           "value": "5", 
           "isSelected": true 
          }, 
          { 
           "title": "15 minutes", 
           "value": "15" 
          }, 
          { 
           "title": "30 minutes", 
           "value": "30" 
          } 
         ] 
        } 
       ], 
       "actions": [ 
        { 
         "type": "Action.Http", 
         "method": "POST", 
         "url": "http://foo.com", 
         "title": "Snooze" 
        }, 
        { 
         "type": "Action.Http", 
         "method": "POST", 
         "url": "http://foo.com", 
         "title": "I'll be late" 
        }, 
        { 
         "type": "Action.Http", 
         "method": "POST", 
         "url": "http://foo.com", 
         "title": "Dismiss" 
        } 
       ] 
     } 
    }); 

    session.send(adaptiveCardMessage); 
    session.endDialog(); 
}); 
関連する問題