当我使用收据卡时,频道线路和信使上是否有消息"Sorry, it looks like something went wrong."



我创建了一个机器人并使用收据代码来显示我的摘要结果。在测试并部署到网络聊天频道时,它没有问题,但是当我将机器人添加到线路频道和信使频道时,我收到此消息"对不起,看起来出了点问题。我检查了我的代码,知道当我使用收据卡时发生了问题。

我的代码(在确认预订步骤异步时出现问题(

namespace Microsoft.BotBuilderSamples
{
public class BookingDataDialog : ComponentDialog
{
private readonly IStatePropertyAccessor<BookingData> _userProfileAccessor;
public BookingDataDialog(UserState userState)
: base(nameof(BookingDataDialog))
{
_userProfileAccessor = userState.CreateProperty<BookingData>("BookingData");
// This array defines how the Waterfall will execute.
var waterfallSteps = new WaterfallStep[]
{
AllowBookingStepAsync,
SelectRoomStepAsync,
EmployeeIdStepAsync,
BookingDateStepAsync,
TimeFromStepAsync,
TimeToStepAsync,
ConfirmBookingStepAsync,
FinalStepAsync
};
// Add named dialogs to the DialogSet. These names are saved in the dialog state.
AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));
AddDialog(new TextPrompt(nameof(TextPrompt)));
AddDialog(new DateTimePrompt(nameof(DateTimePrompt)));
AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt)));
// The initial child Dialog to run.
InitialDialogId = nameof(WaterfallDialog);
}
private async Task<DialogTurnResult> AllowBookingStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
await stepContext.Context.SendActivityAsync(MessageFactory.Text($"ยินดีต้อนรับสู่ตัวช่วยในการจองห้องประชุม"), cancellationToken);
return await stepContext.PromptAsync(nameof(ConfirmPrompt),
new PromptOptions
{
Prompt = MessageFactory.Text("คุณต้องการที่จะทำการจองห้องหรือไม่")
}, cancellationToken);
}
private static async Task<DialogTurnResult> SelectRoomStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
if ((bool)stepContext.Result)
{
return await stepContext.PromptAsync(nameof(ChoicePrompt),
new PromptOptions
{
Prompt = MessageFactory.Text("โปรดเลือกห้องที่ต้องการจอง"),
RetryPrompt = MessageFactory.Text("กรุณาเลือกอีกครั้ง"),
Choices = ChoiceFactory.ToChoices(new List<string> { "Room 1", "Room 2", "Room 3", "Room 4" }),
}, cancellationToken);
}
else
{
return await stepContext.EndDialogAsync();
}
}
private static async Task<DialogTurnResult> EmployeeIdStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var previousResult = ((FoundChoice)stepContext.Result).Value;
switch (previousResult)
{
case "Room 1":
stepContext.Values["AssetId"] = 1;
break;
case "Room 2":
stepContext.Values["AssetId"] = 2;
break;
case "Room 3":
stepContext.Values["AssetId"] = 3;
break;
case "Room 4":
stepContext.Values["AssetId"] = 4;
break;
}
return await stepContext.PromptAsync(nameof(TextPrompt), 
new PromptOptions
{
Prompt = MessageFactory.Text("โปรดใส่รหัสพนักงาน")
}, cancellationToken);
}
private async Task<DialogTurnResult> BookingDateStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
stepContext.Values["EmployeeId"] = (string)stepContext.Result;
return await stepContext.PromptAsync(nameof(DateTimePrompt),
new PromptOptions
{
Prompt = MessageFactory.Text("วันที่คุณต้องการจองคือวันที่เท่าไหร่"),
RetryPrompt = MessageFactory.Text("กรุณาใส่วันที่ให้ถูกต้อง")
}, cancellationToken);
}
private async Task<DialogTurnResult> TimeFromStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var previousResult = (stepContext.Result as IList<DateTimeResolution>)?.FirstOrDefault().Value;
var bookingDate = DateTime.Parse(previousResult);
stepContext.Values["BookingDate"] = bookingDate;
return await stepContext.PromptAsync(nameof(DateTimePrompt),
new PromptOptions
{
Prompt = MessageFactory.Text("เริ่มจองตั้งแต่เวลา ?"),
RetryPrompt = MessageFactory.Text("กรุณาใส่เวลาให้ถูกต้อง")
}, cancellationToken);
}
private async Task<DialogTurnResult> TimeToStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var previousResult = (stepContext.Result as IList<DateTimeResolution>)?.FirstOrDefault().Value;
var timeFrom = DateTime.Parse(previousResult);
stepContext.Values["TimeFrom"] = timeFrom;
return await stepContext.PromptAsync(nameof(DateTimePrompt),
new PromptOptions
{
Prompt = MessageFactory.Text("จองถึงเวลา ?"),
RetryPrompt = MessageFactory.Text("กรุณาใส่เวลาให้ถูกต้อง")
}, cancellationToken);
}
private async Task<DialogTurnResult> ConfirmBookingStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var previousResult = (stepContext.Result as IList<DateTimeResolution>)?.FirstOrDefault().Value;
var timeTo = DateTime.Parse(previousResult).TimeOfDay;
var bookingData = new BookingData();
bookingData.AssetId = (int)stepContext.Values["AssetId"];
bookingData.EmployeeId = (string)stepContext.Values["EmployeeId"];
bookingData.BookingDate = (DateTime)stepContext.Values["BookingDate"];
bookingData.TimeFrom = ((DateTime)stepContext.Values["TimeFrom"]).TimeOfDay;
bookingData.TimeTo = timeTo;
var attachments = new List<Attachment>();
var reply = MessageFactory.Attachment(attachments);
var listFact = new List<Fact>();
listFact.Add(new Fact("ห้องที่", bookingData.AssetId.ToString()));
listFact.Add(new Fact("Employee Id", bookingData.EmployeeId));
listFact.Add(new Fact("วันที่จอง", bookingData.BookingDate.ToString("dd MMM yyyy")));
listFact.Add(new Fact("ช่วงเวลาที่จอง", $"{bookingData.TimeFrom.ToString(@"hh:mm")} - {bookingData.TimeTo.ToString(@"hh:mm")}"));
var summaryBooking = new ReceiptCard
{
Title = "ยืนยันการจอง",
Facts = listFact
};
//Line and Messengers can't show receipt card
reply.Attachments.Add(summaryBooking.ToAttachment());
await stepContext.Context.SendActivityAsync(reply, cancellationToken);
return await stepContext.PromptAsync(nameof(ConfirmPrompt),
new PromptOptions
{
Prompt = MessageFactory.Text("ข้อมูลถูกต้องหรือไม่ ?")
}, cancellationToken);
}
private async Task<DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
if ((bool)stepContext.Result)
{
await stepContext.Context.SendActivityAsync(MessageFactory.Text("ทำการจองสำเร็จ"), cancellationToken);
}
else
{
await stepContext.Context.SendActivityAsync(MessageFactory.Text("ยกเลิกขั้นตอนการจอง"), cancellationToken);
}
return await stepContext.EndDialogAsync();
}
}
}

Messenger 正式支持收据卡,但由于通道连接器错误,它们无法正常工作。我已经在内部提交了该错误。同时,一种解决方法是使用Facebook Messenger的收据模板,并将Messenger平台模板作为频道数据发送。

在 Node.js 中发送收据卡的简单示例:

this.onMessage(async context => {
await context.sendActivity({
channelData: {
'attachment': {
'type': 'template',
'payload': {
'template_type': 'receipt',
'recipient_name': 'Stephane Crozatier',
'order_number': '12345678902',
'currency': 'USD',
'payment_method': 'Visa 2345',        
'order_url': 'http://petersapparel.parseapp.com/order?order_id=123456',
'timestamp': '1428444852',         
'address': {
'street_1': '1 Hacker Way',
'street_2': '',
'city': 'Menlo Park',
'postal_code': '94025',
'state': 'CA',
'country': 'US'
},
'summary': {
'subtotal': 75.00,
'shipping_cost': 4.95,
'total_tax': 6.19,
'total_cost': 56.14
},
'adjustments': [
{
'name': 'New Customer Discount',
'amount': 20
},
{
'name': '$10 Off Coupon',
'amount': 10
}
],
'elements': [
{
'title': 'Classic White T-Shirt',
'subtitle': '100% Soft and Luxurious Cotton',
'quantity': 2,
'price': 50,
'currency': 'USD',
'image_url': 'http://petersapparel.parseapp.com/img/whiteshirt.png'
},
{
'title': 'Classic Gray T-Shirt',
'subtitle': '100% Soft and Luxurious Cotton',
'quantity': 1,
'price': 25,
'currency': 'USD',
'image_url': 'http://petersapparel.parseapp.com/img/grayshirt.png'
}
]
}
}
}
});
});

若要创建实现特定于 LINE 的消息类型的消息,请将活动对象的通道数据属性设置为指定 LINE 消息类型和操作类型的 JSON 对象。这将指导您了解如何将 channelData 属性用于特定于 LINE 的消息。

希望这有帮助。

最新更新