-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.py
47 lines (33 loc) · 1.54 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
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import requests
from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet
class GetTodaysHoroscope(Action):
def name(self):
return "get_todays_horoscope"
def run(self, dispatcher, tracker, domain):
# type: (Dispatcher, DialogueStateTracker, Domain) -> List[Event]
user_horoscope_sign = tracker.get_slot('horoscope_sign')
base_url = "http://horoscope-api.herokuapp.com/horoscope/{day}/{sign}"
url = base_url.format(**{'day': "today", 'sign': user_horoscope_sign})
#http://horoscope-api.herokuapp.com/horoscope/today/capricorn
res = requests.get(url)
todays_horoscope = res.json()['horoscope']
response = "Your today's horoscope:\n{}".format(todays_horoscope)
dispatcher.utter_message(response)
return [SlotSet("horoscope_sign", user_horoscope_sign)]
class SubscribeUser(Action):
def name(self):
return "subscribe_user"
def run(self, dispatcher, tracker, domain):
# type: (Dispatcher, DialogueStateTracker, Domain) -> List[Event]
subscribe = tracker.get_slot('subscribe')
if subscribe == "True":
response = "You're successfully subscribed"
if subscribe == "False":
response = "You're successfully unsubscribed"
dispatcher.utter_message(response)
return [SlotSet("subscribe", subscribe)]