“类型错误:无法读取属性‘得到’的未定义”的上下文数据
我跑,谷歌/ 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
我是犯罪嫌疑人(虽然高度怀疑),其原因可能是,实施例中,他们使用“代理”和旧的语法,因为我使用的AOG语法,其中。
任何建议/帮助是非常感谢!
回答如下:你是八九不离十。
这些应该是物业contexts
用一个“s”结尾。
它看起来像您使用的行动上,谷歌图书馆,通常具有conv
对象,并使用contexts
财产与get()
,set()
和delete()
方法来访问上下文。
如果您使用的dialogflow履行库(你没有),它往往有一个agent
对象,并使用context
属性(不带“s”)来访问类似get()
,set()
和delete()
方法。