forked from SHARATHbhushan/speech_module_client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialogue_server.py
executable file
·42 lines (30 loc) · 908 Bytes
/
dialogue_server.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
#!/usr/bin/env python3
from rasa_ros.srv import Dialogue, DialogueResponse
import rospy
import requests
def handle_service(req):
input_text = req.input_text
# Get answer
get_answer_url = 'http://localhost:5002/webhooks/rest/webhook'
message = {
"sender": 'bot',
"message": input_text
}
r = requests.post(get_answer_url, json=message)
response = DialogueResponse()
response.answer = ""
for i in r.json():
response.answer += i['text'] + ' ' if 'text' in i else ''
return response
def main():
# Server Initialization
rospy.init_node('dialogue_service')
s = rospy.Service('dialogue_server',
Dialogue, handle_service)
rospy.logdebug('Dialogue server READY.')
rospy.spin()
if __name__ == '__main__':
try:
main()
except rospy.ROSInterruptException as e:
pass