Я использую код, который Google / dialogflow предоставил на их веб-сайте ( Ссылка) и по какой-то причине он продолжает выдавать эту ошибку каждый раз, когда я запускаю намерение, которое я хочу вызвать:
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.
Любые предложения / помощь приветствуются!