Answered by:
Adaptive card in AZURE bot service connected to LUIS

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' })
- Edited by jojo_h Tuesday, July 31, 2018 2:29 AM
- Moved by Micah McKittrickMicrosoft employee Tuesday, July 31, 2018 4:59 PM
Tuesday, July 31, 2018 2:24 AM
Answers
-
The query posted by you has not reached the right forum. In order to assist best on your query, I would request you to post your query in SO => Azure LUIS dedicated support. Additionally, adding the [Azure] tag on SO will increase visibility as it is a Microsoft Sponsored tag.
https://stackoverflow.com/questions/tagged/LUIS
https://stackoverflow.com/questions/tagged/botframework
This will assist you with a faster reply to your query.
- Proposed as answer by Dave PatrickMVP Tuesday, July 31, 2018 6:31 PM
- Marked as answer by Dave PatrickMVP Monday, August 6, 2018 6:51 PM
Tuesday, July 31, 2018 2:41 AM