-
Notifications
You must be signed in to change notification settings - Fork 2
/
actions.py
49 lines (40 loc) · 1.83 KB
/
actions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet, FollowupAction, AllSlotsReset
from rasa_sdk.executor import CollectingDispatcher
from utils import *
# class ActionHelloWorld(Action):
#
# def name(self) -> Text:
# return "action_hello_world"
#
# def run(self, dispatcher: CollectingDispatcher,
# tracker: Tracker,
# domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#
# dispatcher.utter_message("Hello World!")
#
# return []
class ActionReadBook(Action):
def name(self) -> Text:
return 'action_read_book'
def run(self, dispatcher, tracker: Tracker, domain: Dict[Text, Any]):
book_genre_type = tracker.get_slot('book_slot_value')
if book_genre_type != 'Others':
if book_genre_type == "Avelene's Choice":
book_details = fetch_books_avelene_choice()
dispatcher.utter_message('These are the best books I have found:\n{}'.format(book_details))
else:
book_details = fetch_books_categorywise(book_genre_type)
dispatcher.utter_message('These are the best books I have found:\n{}'.format(book_details))
return [FollowupAction('action_listen')]
elif book_genre_type == "Others":
return [FollowupAction('action_listen')]
class ActionSearchBook(Action):
def name(self) -> Text:
return 'action_search_book'
def run(self, dispatcher, tracker: Tracker, domain: Dict[Text, Any]):
book_name = tracker.latest_message['text']
book_details = fetch_books_user_search(book_name)
dispatcher.utter_message('These are the details of the book you are looking for:\n{}'.format(book_details))
return [SlotSet('search_book_name', book_name), FollowupAction('action_listen')]