Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import { WebhookClient, Text } from "dialogflow-fulfillment";
  2.  
  3. const HOUR_INTENT = "HourIntent"; //Agregamos el nombre del nuevo intent
  4. const ORDER_FOOD = "OrderFood";
  5.  
  6. export default class DialogflowBot {
  7. constructor() {
  8. this.actionMap = new Map();
  9. this.actionMap.set(HOUR_INTENT, this.getCurrentTime.bind(this)); //Relacionamos el nuevo intent con la función
  10. this.actionMap.set(ORDER_FOOD, this.orderFood.bind(this));
  11. }
  12.  
  13. async handle(req, res) {
  14. const agent = new WebhookClient({ request: req, response: res });
  15. await agent.handleRequest(this.actionMap);
  16. }
  17.  
  18. // Creamos una nueva función que devuelva la hora
  19. getCurrentTime(agent) {
  20. console.log(agent);
  21. const today = new Date();
  22. const currentTime =
  23. today.getHours() +
  24. ":" +
  25. (today.getMinutes().toString().length == 2
  26. ? today.getMinutes()
  27. : today.getMinutes() * 10);
  28. const text = new Text(currentTime);
  29. agent.add(text);
  30. }
  31.  
  32. orderFood(agent) {
  33. agent.add(
  34. "Su comida " +
  35. agent.parameters["FoodCategory"] +
  36. " llegará en 45 minutos."
  37. );
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement