Closed TranNgocKhoa closed 6 years ago
I ran the following code with no problems:
public IMessageActivity GetRooms(IMessageActivity message)
{
using (WebClient wc = new WebClient())
{
// wc.Headers.Add(header: HttpRequestHeader.ContentType, value: "application/json; charset=utf-8");
// var json = (wc.DownloadString(HostValueUtils.GETALLROOM));
//List<Room> postList = (List<Room>)Newtonsoft.Json.JsonConvert.DeserializeObject(json, typeof(List<Room>));
////postList = postList.GetRange(0, 9);
message.AttachmentLayout = AttachmentLayoutTypes.Carousel;
// foreach (Room p in postList)
// {
for (int i = 0; i < 5; i++)
{
List<CardImage> imgList = new List<CardImage>
{
new CardImage(@"https://i.imgur.com/vAHUOP5.png")
};
var heroCard = new HeroCard
{
Title = "nachos" ,
Text = "nachos",
Images = imgList,
Buttons = new List<CardAction> { new CardAction(ActionTypes.PostBack, "stuff", value: "things") }
};
message.Attachments.Add(heroCard.ToAttachment());
}
// }
return message;
}
}
when calling that method like this:
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
var reply = activity.CreateReply();
GetRooms(reply);
await context.PostAsync(reply);
context.Wait(MessageReceivedAsync);
}
The issue seems to be that facebook does like something in the code I had to comment out because I did not have everything to make it resolve. This is really as far as i can look into it with the code given, hope it helps.
Actually, I have a simillar code bellow, and it works on Facebook Messenger:
public IMessageActivity GetRoomTypes(IMessageActivity message)
{
using (WebClient wc = new WebClient())
{
wc.Headers.Add(header: HttpRequestHeader.ContentType, value: "application/json; charset=utf-8");
var json = (wc.DownloadString(HostValueUtils.GETALLROOMTYPE));
List<RoomType> items = (List<RoomType>)Newtonsoft.Json.JsonConvert.DeserializeObject(json, typeof(List<RoomType>));
message.AttachmentLayout = AttachmentLayoutTypes.Carousel;
foreach (RoomType p in items)
{
var heroCard = new HeroCard
{
Title = p.Name,
Subtitle = p.Description,
};
message.Attachments.Add(heroCard.ToAttachment());
}
return message;
}
}
And I call the method above here
[LuisIntent("RoomType")]
public async Task RoomTypeInfo(IDialogContext context, LuisResult result)
{
using (RoomTypeService roomTypeService = new RoomTypeService())
{
//I call here
var message = roomTypeService.GetRoomTypes(context.MakeMessage());
await context.PostAsync(message);
context.Wait(this.MessageReceived);
}
}
You can download my code here https://github.com/15110064/StupidBotMessengerMultiDialogs
@TranNgocKhoa Is this resolved for you, or did you still need help looking into it?
Closing due to inactivity. Please open a new issue if you require further assistance.
Bot Info
Issue Description
I'm trying to get and display data from web Api by Herocard. This work properly on Emulator, Web Chat but on Facebook Messenger, this give me an Error: Failed with message: Operation returned an invalid status code 'BadRequest'
Code Example
This return an IMessageActivity HostValueUtils.GETALLROOM is "https://sohot-webapp.azurewebsites.net/api/room/getallparents"
I get IMessageActivity here:
Room class:
Reproduction Steps
Expected Behavior
Work properly like Emulator and Web Chat.
Actual Results
Failed with message: Operation returned an invalid status code 'BadRequest'