locked
Adaptive card in AZURE bot service connected to LUIS RRS feed

  • Question

  • I just recently create a bot about searching weather on Azure web app bot and connect to LUIS. I use "request" and "cheerio" to get weather from government website. And i want to put the data i get from the website into the adaptive card(microsoft service). And i found adaptive card couldn't get the variable I set (called "weathermessage") to store weather. It's all written in node.js on App Service Editor.Below is my code related to get weather and card.
    var weathermessage = "";
    var weathers = "";
    var url = 'https://www.cwb.gov.tw/V7/forecast/taiwan/New_Taipei_City.htm';
    request(url,(err, res, body) => {
    var $ = cheerio.load(body);
    var weather = [];
    $('#box8 .FcstBoxTable01 tbody tr').each(function() {
      weather.push($(this).text().split('\n'));
      console.log(weather);
    });
          weather = weather.map(weathers =>({
          Time: weathers[1].substring(2).split(' ')[0],
          Temp: weathers[2].substring(2),
          Feel: weathers[5].substring(2),
          Rain: weathers[6].substring(2).split("\n")
         }));
         console.log(weathers);
         weathermessage = weather.map(function(weathers){
        return  weathers.Time + 'Temperature: '  + weathers.Temp +' ,Comfort: '+ weathers.Feel + ' ,Rain Possibility: ' +weathers.Rain+'\n';    
    }).join("\n");

    var card ={
            "contentType" : "application/vnd.microsoft.card.adaptive",
            "content": {
        "type": "AdaptiveCard",
        "body": [
            {
                "type": "TextBlock",
                "text": "Weather Check",
                "size":"large"
            },
        ],
     
        "actions":[
            {
                "type": "Action.ShowCard",
                "title": "Taipei",
                "card": {
                    "type": "AdaptiveCard",
                    "style": "emphasis",
                    "body": [
                        {
                            "type": "TextBlock",
                            "text": "Taipei's weather:"
                        },
                        {
                            "type":"TextBlock",
                            "text": "taipei's weather {{weathermessage}} ",
                            "wrap":true
                        }
                    ]
                }
            },
                    {
                "type": "Action.ShowCard",
                "title": "Taichung",
                "card": {
                    "type": "AdaptiveCard",
                    "style": "emphasis",
                    "body": [
                        {
                            "type": "TextBlock",
                            "text": "Taichung's weather"
                        },
                        {
                            "type": "TextBlock",
                            "text": {weathermessage}
                        }
                    ]
                }
            },
                    {
                "type": "Action.ShowCard",
                "title": "Taoyuan",
                "card": {
                    "type": "AdaptiveCard",
                    "style": "emphasis",
                    "body": [
                        {
                            "type": "TextBlock",
                            "text": "Taoyuan's weather"
                        },
                        {
                            "type": "TextBlock",
                            "text": {weathermessage}
                        }
                    ]
                }
            }
        ],
        "version": "1.0"
    }
    }
    bot.dialog('WeatherDialog',
        (session) => {
             session.send(weathermessage);
             var msg = new builder.Message(session)
         .addAttachment(card); //addAttachment    
     
           session.send(msg);
           session.send('You reached the Cancel intent. You said \'%s\'.', session.message.text);
    
            // Send the activity to the user.
            session.endDialog();
        }
    ).triggerAction({
        matches: 'Weather'
    })




    Tuesday, July 31, 2018 2:24 AM

Answers