Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { WebhookClient, Text } from "dialogflow-fulfillment";
- const HOUR_INTENT = "HourIntent"; //Agregamos el nombre del nuevo intent
- const ORDER_FOOD = "OrderFood";
- export default class DialogflowBot {
- constructor() {
- this.actionMap = new Map();
- this.actionMap.set(HOUR_INTENT, this.getCurrentTime.bind(this)); //Relacionamos el nuevo intent con la función
- this.actionMap.set(ORDER_FOOD, this.orderFood.bind(this));
- }
- async handle(req, res) {
- const agent = new WebhookClient({ request: req, response: res });
- await agent.handleRequest(this.actionMap);
- }
- // Creamos una nueva función que devuelva la hora
- getCurrentTime(agent) {
- console.log(agent);
- const today = new Date();
- const currentTime =
- today.getHours() +
- ":" +
- (today.getMinutes().toString().length == 2
- ? today.getMinutes()
- : today.getMinutes() * 10);
- const text = new Text(currentTime);
- agent.add(text);
- }
- orderFood(agent) {
- agent.add(
- "Su comida " +
- agent.parameters["FoodCategory"] +
- " llegará en 45 minutos."
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement