11
11
import os
12
12
import sparrow_handler as sparrow
13
13
from time import sleep
14
-
14
+ from threading import Thread
15
15
import paho .mqtt .publish as publish
16
16
17
17
with open ('config.json' ) as config_file :
@@ -54,13 +54,16 @@ def listen_input():
54
54
55
55
#Handling @sparrow commands
56
56
if sparrow .is_sparrow_request (message ):
57
- sparrow .handle_sparrow_request (from_no , message )
57
+ t = Thread (target = sparrow .handle_sparrow_request , args = (from_no , message ,))
58
+ t .start ()
59
+ # sparrow.handle_sparrow_request(from_no, message)
58
60
return str (MessagingResponse ())
59
61
60
62
receiver = db .getReceiver (from_no )
61
63
if receiver == db .IBM_RECEIVER :
62
64
if sparrow .is_command (message ):
63
- sparrow .handle_command (from_no , message )
65
+ t = Thread (target = sparrow .handle_command , args = (from_no , message ))
66
+ t .start ()
64
67
return str (MessagingResponse ())
65
68
elif num_media > 0 :
66
69
reply = "Sorry! Our Automated chatbot doesn't support Media at this point."
@@ -69,7 +72,8 @@ def listen_input():
69
72
else :
70
73
replies = chatbot .handle_message (from_no , message )
71
74
if len (replies ) > 1 :
72
- messaging .send_messages (from_no , replies )
75
+ t = Thread (target = messaging .send_messages , args = (from_no , replies ))
76
+ t .start ()
73
77
return (str (MessagingResponse ()))
74
78
else :
75
79
reply = replies [0 ]
@@ -103,19 +107,19 @@ def handle_mqtt_message(client, userdata, message):
103
107
104
108
if sparrow .is_sparrow_request (message ):
105
109
sparrow .handle_sparrow_request (from_no , message )
106
- return str ( MessagingResponse ())
110
+ return
107
111
108
112
receiver = db .getReceiver (from_no )
109
113
print (receiver )
110
114
if receiver == db .IBM_RECEIVER :
111
115
if sparrow .is_command (message ):
112
116
sparrow .handle_command (from_no , message )
113
- return str ( MessagingResponse ())
117
+ return
114
118
115
119
reply = chatbot .handle_message (from_no , message )
116
120
for message in reply :
117
121
mqtt .publish (data ["topic" ].replace ("receive" , "response" ), message )
118
- sleep (1 )
122
+ sleep (2 )
119
123
return
120
124
else :
121
125
messaging .send_message (receiver , message )
@@ -150,4 +154,3 @@ def entities_of_text():
150
154
app .run (host = '0.0.0.0' , port = 5000 , debug = False )
151
155
else :
152
156
app .run (host = '0.0.0.0' , port = int (cf_port ), debug = False )
153
-
0 commit comments