forked from artificial-nikhita/starter-pack-rasa-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.py
27 lines (22 loc) · 843 Bytes
/
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
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
import requests
import json
from rasa_core_sdk import Action
logger = logging.getLogger(__name__)
class ActionJoke(Action):
def name(self):
# define the name of the action which can then be included in training stories
return "action_joke"
def run(self, dispatcher, tracker, domain):
# what your action should do
request = json.loads(
requests.get("https://api.chucknorris.io/jokes/random").text
) # make an api call
joke = request["value"] # extract a joke from returned json response
dispatcher.utter_message(joke) # send the message back to the user
return []