"TypeError: Cannot read property 'get' of undefined" for contextual data
"TypeError: Cannot read property 'get' of undefined" for contextual data
我是 运行 Google/ dialogflow 在其网站上提供的代码(Link) 并且出于某种原因,每次我触发意图时它都会抛出此错误我是想要调用:
TypeError: Cannot read property 'get' of undefined
这是我的代码:
app.intent('Make Appointment' , (conv) => {
// This variable needs to hold an instance of Date object that specifies the start time of the appointment.
const dateTimeStart = convertTimestampToDate(conv.parameters.date,
conv.parameters.time);
// This variable holds the end time of the appointment, which is calculated by adding an hour to the start time.
const dateTimeEnd = addHours(dateTimeStart, 1);
// Convert the Date object into human-readable strings.
const appointmentTimeString = getLocaleTimeString(dateTimeStart);
const appointmentDateString = getLocaleDateString(dateTimeStart);
// The checkCalendarAvailablity() function checks the availability of the time slot.
return checkCalendarAvailablity(dateTimeStart, dateTimeEnd).then(() => {
// The time slot is available.
// The function returns a response that asks for the confirmation of the date and time.
conv.ask(`Okay, ${appointmentDateString} at ${appointmentTimeString}. Did I get that right?`);
}).catch(() => {
// The time slot is not available.
conv.add(`Sorry, we're booked on ${appointmentDateString} at ${appointmentTimeString}. Is there anything else I can do for you?`);
// Delete the context 'MakeAppointment-followup' to return the flow of conversation to the beginning.
conv.context.delete('MakeAppointment-followup');
});
});
app.intent('Make Appointment - yes', (conv) => {
// Get the context 'MakeAppointment-followup'
const context = conv.context.get('MakeAppointment-followup');
// This variable needs to hold an instance of Date object that specifies the start time of the appointment.
const dateTimeStart = convertTimestampToDate(context.parameters.date, context.parameters.time);
// This variable holds the end time of the appointment, which is calculated by adding an hour to the start time.
const dateTimeEnd = addHours(dateTimeStart, 1);
// Convert the Date object into human-readable strings.
const appointmentTimeString = getLocaleTimeString(dateTimeStart);
const appointmentDateString = getLocaleDateString(dateTimeStart);
// Delete the context 'MakeAppointment-followup'; this is the final step of the path.
conv.context.delete('MakeAppointment-followup');
// The createCalendarEvent() function checks the availability of the time slot and marks the time slot on Google Calendar if the slot is available.
return createCalendarEvent(dateTimeStart, dateTimeEnd).then(() => {
conv.add(`Got it. I have your reservation scheduled on ${appointmentDateString} at ${appointmentTimeString}!`);
}).catch(() => {
conv.add(`Sorry, something went wrong. I couldn't book the ${appointmentDateString} at ${appointmentTimeString}. Is there anything else I can help you with?`);
});
});
(抱歉,代码很长,但我觉得这个问题很有必要)
这两个功能所做的就是预约(或预订)并为其添加确认步骤。因此,例如,如果一切顺利,它看起来像这样:
User: I'd like to make an appointment
bot: Sure, what day works for you?
User: Tomorrow
bot: what time?
User: At 6 pm
bot: Okay, February 11 at 6pm, did I get that right?
User: Yes // Part where it stops working
Bot: Great, I have your appointment booked for February 11 at 6pm! // App crashes at this part
我怀疑(尽管非常怀疑)原因可能是在示例中他们使用的是 "agent" 和旧语法,而我使用的是 AOG 语法。
非常感谢任何建议/帮助!
我是 运行 Google/ dialogflow 在其网站上提供的代码(Link) 并且出于某种原因,每次我触发意图时它都会抛出此错误我是想要调用:
TypeError: Cannot read property 'get' of undefined
这是我的代码:
app.intent('Make Appointment' , (conv) => {
// This variable needs to hold an instance of Date object that specifies the start time of the appointment.
const dateTimeStart = convertTimestampToDate(conv.parameters.date,
conv.parameters.time);
// This variable holds the end time of the appointment, which is calculated by adding an hour to the start time.
const dateTimeEnd = addHours(dateTimeStart, 1);
// Convert the Date object into human-readable strings.
const appointmentTimeString = getLocaleTimeString(dateTimeStart);
const appointmentDateString = getLocaleDateString(dateTimeStart);
// The checkCalendarAvailablity() function checks the availability of the time slot.
return checkCalendarAvailablity(dateTimeStart, dateTimeEnd).then(() => {
// The time slot is available.
// The function returns a response that asks for the confirmation of the date and time.
conv.ask(`Okay, ${appointmentDateString} at ${appointmentTimeString}. Did I get that right?`);
}).catch(() => {
// The time slot is not available.
conv.add(`Sorry, we're booked on ${appointmentDateString} at ${appointmentTimeString}. Is there anything else I can do for you?`);
// Delete the context 'MakeAppointment-followup' to return the flow of conversation to the beginning.
conv.context.delete('MakeAppointment-followup');
});
});
app.intent('Make Appointment - yes', (conv) => {
// Get the context 'MakeAppointment-followup'
const context = conv.context.get('MakeAppointment-followup');
// This variable needs to hold an instance of Date object that specifies the start time of the appointment.
const dateTimeStart = convertTimestampToDate(context.parameters.date, context.parameters.time);
// This variable holds the end time of the appointment, which is calculated by adding an hour to the start time.
const dateTimeEnd = addHours(dateTimeStart, 1);
// Convert the Date object into human-readable strings.
const appointmentTimeString = getLocaleTimeString(dateTimeStart);
const appointmentDateString = getLocaleDateString(dateTimeStart);
// Delete the context 'MakeAppointment-followup'; this is the final step of the path.
conv.context.delete('MakeAppointment-followup');
// The createCalendarEvent() function checks the availability of the time slot and marks the time slot on Google Calendar if the slot is available.
return createCalendarEvent(dateTimeStart, dateTimeEnd).then(() => {
conv.add(`Got it. I have your reservation scheduled on ${appointmentDateString} at ${appointmentTimeString}!`);
}).catch(() => {
conv.add(`Sorry, something went wrong. I couldn't book the ${appointmentDateString} at ${appointmentTimeString}. Is there anything else I can help you with?`);
});
});
(抱歉,代码很长,但我觉得这个问题很有必要)
这两个功能所做的就是预约(或预订)并为其添加确认步骤。因此,例如,如果一切顺利,它看起来像这样:
User: I'd like to make an appointment
bot: Sure, what day works for you?
User: Tomorrow
bot: what time?
User: At 6 pm
bot: Okay, February 11 at 6pm, did I get that right?
User: Yes // Part where it stops working
Bot: Great, I have your appointment booked for February 11 at 6pm! // App crashes at this part
我怀疑(尽管非常怀疑)原因可能是在示例中他们使用的是 "agent" 和旧语法,而我使用的是 AOG 语法。
非常感谢任何建议/帮助!