Skip to content

Instantly share code, notes, and snippets.

@luddilo
Last active April 20, 2020 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luddilo/be837a6881445e7100a9a44e76e7acf5 to your computer and use it in GitHub Desktop.
Save luddilo/be837a6881445e7100a9a44e76e7acf5 to your computer and use it in GitHub Desktop.
// This will have to be hosted by you elsewhere, maybe as a cloud function..!
const checkIfSessionHasARecentFlightBooking = (sessionId) => {
// ...
}
export const checkStatus = (req, res) => {
const { sessionId } = req.body
return res.json({
set: {
recentlyBooked: checkIfSessionHasARecentFlightBooking(sessionId)
}
})
}
import { BotTurn } from "narratory"
import * as nlu from "./nlu"
const queryHelp: BotTurn = {
say: {
text: "Hi, I am your travel partner. How can I help?",
suggestions: ["Book a flight", "Book a room"],
},
user: [
{
intent: nlu.BookRoomIntent,
bot: {
// First we query this endpoint to see the status (see third file)
url: "https://endpoint-to-check-if-recently-booked.com/checkStatus",
bot: [
{
// If recently booked (this variable is set from the backend), we ask if we want a room for the same location
cond: { recentlyBooked: true },
say: "Do you want to book a room for _flightLocation",
user: [
{
intent: nlu.Yes,
bot: {
say: "Great!",
set: { roomLocation: "_flightLocation" },
},
},
{ intent: nlu.No, bot: "Okay!" },
],
},
{
// If no recent booking, we just confirm the user's intent and then move to the next turn in the dialog below
say: "Booking a room it is",
},
],
},
},
],
}
const queryLocation: BotTurn = {
// We only ask this question if we haven't already set the roomLocation
cond: { roomLocation: true },
say: "What is the destination?",
user: [
{
intent: nlu.LocationIntent,
bot: {
say: "Okay, _location it is",
set: { roomLocation: "_location" },
},
},
],
}
// Our narrative, ie sequence of bot turns
export const narrative = [queryHelp, queryLocation]
import { Intent, entities } from "narratory"
export const BookRoomIntent: Intent = {
examples: ["I want to book a room", "booking a room", "I want a room"],
}
export const LocationIntent: Intent = {
entities: {
// Built in Dialogflow entity
location: entities.geoCity,
},
examples: ["_location", "the destination is _location"],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment