Last active
April 20, 2020 09:15
-
-
Save luddilo/be837a6881445e7100a9a44e76e7acf5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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