This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateVolunteer(TaskQueue): | |
def __init__(self, r): | |
super().__init__(r, 'createVolunteer') | |
def respond(self, m): | |
message = { | |
'message_id': 'GreetVolunteer', | |
'number': m['number'] | |
} | |
self.sendSMS(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Feed(): | |
def __init__(self, r, qName): | |
self.redis = r | |
self.name = qName | |
def sendSMS(self, message): | |
self.redis.rpush('sendSMSQueue', json.dumps(message)) | |
def respond(self, m): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TaskQueue(Feed): | |
def __init__(self, r, qName): | |
super().__init__(r, qName) | |
self.type = "task" | |
def get_message(self): | |
val = self.redis.lpop(self.name) | |
if not val: | |
return | |
return json.loads(val.decode("utf-8")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handleReply(self, message): | |
lastMessage = self.readLQCache(message['number']) | |
if lastMessage: | |
replySchema = self.getExpectedReply(lastMessage) | |
if replySchema: | |
matchedReply = False | |
for option in replySchema['options']: | |
if message['body'] in option['responses']: | |
matchedReply = True | |
self.clearLQCache(message['number']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sendMessage(self, message): | |
self.sendSMS(message) | |
if 'message_id' in message: | |
if self.doesMessageExpectReply(message['message_id']): | |
self.updateLQCache(message['number'], message['message_id']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def updateLQCache(self, number, message_id): | |
return self.redisClient.hset('LQ', number, message_id) | |
def readLQCache(self, number): | |
message = self.redisClient.hget('LQ', number) | |
if message: | |
return message.decode("utf-8") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (redis)=>{ | |
function recieve(req, res, next){ | |
if(req.body && req.body.Body && req.body.From){ | |
redis.rpush('recievedQueue', JSON.stringify({ | |
'number': req.body.From, | |
'body': req.body.Body | |
})); | |
return; | |
} | |
res.status(404).json({err: 'Bad text.', code: 404}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SmsApi = Router(); | |
SmsApi.post('/', Sms.recieve); | |
router.use('/sms/', SmsApi); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sendSMS(self, message): | |
try: | |
if 'message_id' in message: | |
self.twilio.messages.create( | |
body=messages.MASTER_LIST[message['message_id']]['body'], | |
from_= config.TWILIO['from_'], | |
to = message['number'] | |
) | |
elif 'message' in message: | |
self.twilio.messages.create( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MASTER_LIST = { | |
"default":{ | |
"body": "We weren't expecting a reply from you! Sign up on whatnow.co to join the community!" | |
}, | |
"GreetVolunteer": { | |
"body": "We appreciate you! Do you understand your resposibilities and feel comfortable with this role? (You can review them at whatnow.co/greet-volunteer) Reply Y/N", | |
"expectsReply": { | |
"options":[ | |
{ | |
"responses": ['y', 'Y', 'YES', 'yes', 'Yes'], |