-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdialogflow_emulator.py
53 lines (45 loc) · 1.62 KB
/
dialogflow_emulator.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
50
51
52
53
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from builtins import str
import uuid
from datetime import datetime
from typing import Any
from typing import Dict
from typing import Text
from typing import List
from rasa_nlu.emulators import NoEmulator
class DialogflowEmulator(NoEmulator):
def __init__(self):
# type: () -> None
super(DialogflowEmulator, self).__init__()
self.name = 'api'
def normalise_response_json(self, data):
# type: (Dict[Text, Any]) -> Dict[Text, Any]
"""Transform data to Dialogflow format."""
return {
"id": str(uuid.uuid1()),
"result": {
"action": data['next_action'],
"actionIncomplete": str(data['tracker']['slots']['requested_slot']!=None),
"fulfillment": {
"speech": data['reply']
},
"metadata": {
"intentId": str(uuid.uuid1()),
"intentName": data['tracker']['latest_message']['intent']['name'],
"webhookForSlotFillingUsed": "false",
"webhookUsed": "false"
},
"parameters": data['tracker']['slots'],
"resolvedQuery": data['reply'],
"source": "agent"
},
"sessionId": data['tracker']['sender_id'],
"status": {
"code": 200,
"errorType": "success"
},
"timestamp": datetime.now().isoformat()
}