Skip to content

Commit

Permalink
twilio bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lmessinger committed Feb 13, 2019
1 parent d077b58 commit cb56df3
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion server/FSM/actions/CalcDateDiff.js
Expand Up @@ -96,7 +96,7 @@ class CalcDateDiff extends Action {

function validCompositeField(field) {

var bool1 = field && (field.indexOf('context.') === 0 || field.indexOf('global.') === 0 || field.indexOf('volatile.') === 0 || field.indexOf('fsm.') === 0);
var bool1 = field && (field.indexOf('message.') === 0 || field.indexOf('context.') === 0 || field.indexOf('global.') === 0 || field.indexOf('volatile.') === 0 || field.indexOf('fsm.') === 0);
var bool2 = field && (field.indexOf('\'') === 0 || field.indexOf('"') === 0 || !isNaN(field));
return bool1 || bool2;
}
Expand Down
2 changes: 1 addition & 1 deletion server/FSM/actions/SetFieldAction.js
Expand Up @@ -79,7 +79,7 @@ class SetFieldAction extends Action {

function validCompositeField(field) {

return field && (field.indexOf('context.') === 0 || field.indexOf('global.') === 0 || field.indexOf('volatile.') === 0 || field.indexOf('fsm.') === 0);
return field && (field.indexOf('message.') === 0 || field.indexOf('context.') === 0 || field.indexOf('global.') === 0 || field.indexOf('volatile.') === 0 || field.indexOf('fsm.') === 0);
}

return [{
Expand Down
2 changes: 1 addition & 1 deletion server/FSM/conditions/IsValidField.js
Expand Up @@ -234,7 +234,7 @@ class IsValidField extends Condition {

function validCompositeField(field) {

var bool1 = field && (field.indexOf('context.') === 0 || field.indexOf('global.') === 0 || field.indexOf('volatile.') === 0 || field.indexOf('fsm.') === 0);
var bool1 = field && (field.indexOf('message.') === 0 || field.indexOf('context.') === 0 || field.indexOf('global.') === 0 || field.indexOf('volatile.') === 0 || field.indexOf('fsm.') === 0);
var bool2 = field && (field.indexOf('\'') === 0 || field.indexOf('"') === 0 || !isNaN(field));
return bool1 || bool2;
}
Expand Down
23 changes: 7 additions & 16 deletions server/chat/twilio.js
Expand Up @@ -87,27 +87,20 @@ class TwilioDriver extends ChatDriverInterface {
send1Message(msg, process) {

if (msg) {
this._timeoutSet = true;
_clients[process.fsm_id].clientFunc.sendMessage(msg, (err, responseData) => { //this function is executed when a response is received from Twilio

if (!err) { // "err" is an error received during the request, if any

// "responseData" is a JavaScript object containing data received from Twilio.
// A sample response from sending an SMS message is here (click "JSON" to see how the data appears in JavaScript):
// http://www.twilio.com/docs/api/rest/sending-sms#example-1
dblogger.log('twilio message sent', responseData.from, responseData.body.substring(0, 20) + '...'); // outputs "+14506667788" 'aslkasdjf'


setTimeout(() => {
msg = _clients[process.fsm_id].messages.pop();
this.send1Message(msg, process);
}, this.timeoutMs);
} else {
dblogger.error('twilio message err', err.message + ' ' + err.moreInfo, msg);
}
});

// if no more to send, AND delay passed, cancel timer
if (_clients[process.fsm_id].messages.length) {
clearInterval(_clients[process.fsm_id].intervalId);
_clients[process.fsm_id].intervalId = undefined;
}
}
}

Expand Down Expand Up @@ -159,18 +152,16 @@ class TwilioDriver extends ChatDriverInterface {
//Send an SMS text message
try {
// if no timer yet
if (_clients[process.fsm_id].intervalId == undefined) {
if (!_clients[process.fsm_id].messages.length) {
// this one, send now
this.send1Message(msg, process);
dblogger.log('message ' + msg.body + 'sent immediatly');
// and set a timer for next ones
_clients[process.fsm_id].intervalId = setInterval(this.send1Message, this.timeoutMs, null, process);
dblogger.log('message ' + msg.body + ' sent immediatly');
resolve('sent immediatly');
} else {
// push subsequent
_clients[process.fsm_id].messages.push(msg);

dblogger.log('message ' + msg.body + 'queued');
dblogger.log('message ' + msg.body + ' queued');
resolve('message queued');
}

Expand Down
2 changes: 1 addition & 1 deletion server/convocode/anonymous/settings.json
@@ -1 +1 @@
{"zoom_initial":1,"zoom_min":0.25,"zoom_max":2,"zoom_step":0.25,"snap_x":2,"snap_y":2,"snap_offset_x":0,"snap_offset_y":0,"layout":"vertical","max_history":100,"background_color":"#000000","selection_color":"#4BB2FD","block_border_color":"#6D6D6D","block_symbol_color":"#333333","anchor_background_color":"#EFEFEF","connection_color":"#00c7cf","root_color":"#FFFFFF","decorator_color":"#ff8c55","composite_color":"#ffffff","tree_color":"#80ff80","action_color":"#8080ff","condition_color":"#00ffff","mlmodel_color":"#ffff80","connection_width":2,"anchor_border_width":2,"anchor_radius":5,"anchor_offset_x":4,"anchor_offset_y":0,"block_border_width":2,"block_root_width":40,"block_root_height":40,"block_tree_width":160,"block_tree_height":40,"block_composite_width":40,"block_composite_height":40,"block_decorator_width":60,"block_decorator_height":60,"block_action_width":160,"block_action_height":40,"block_condition_width":160,"block_condition_height":40,"block_mlmodel_width":160,"block_mlmodel_height":40,"editor":{"leftSelectedTab":"Nodes","rightSelectedTab":"chat sim"},"clientPanel":{"showClient":true}}
{"zoom_initial":1,"zoom_min":0.25,"zoom_max":2,"zoom_step":0.25,"snap_x":2,"snap_y":2,"snap_offset_x":0,"snap_offset_y":0,"layout":"vertical","max_history":100,"background_color":"#000000","selection_color":"#4BB2FD","block_border_color":"#6D6D6D","block_symbol_color":"#333333","anchor_background_color":"#EFEFEF","connection_color":"#00c7cf","root_color":"#FFFFFF","decorator_color":"#ff8c55","composite_color":"#ffffff","tree_color":"#80ff80","action_color":"#8080ff","condition_color":"#00ffff","mlmodel_color":"#ffff80","connection_width":2,"anchor_border_width":2,"anchor_radius":5,"anchor_offset_x":4,"anchor_offset_y":0,"block_border_width":2,"block_root_width":40,"block_root_height":40,"block_tree_width":160,"block_tree_height":40,"block_composite_width":40,"block_composite_height":40,"block_decorator_width":60,"block_decorator_height":60,"block_action_width":160,"block_action_height":40,"block_condition_width":160,"block_condition_height":40,"block_mlmodel_width":160,"block_mlmodel_height":40,"editor":{"leftSelectedTab":"Nodes","rightSelectedTab":"Properties"},"clientPanel":{"showClient":true}}
2 changes: 1 addition & 1 deletion server/utils/dblogger.js
Expand Up @@ -150,7 +150,7 @@ DBLogger.log = function () {
_lastLine = thisArgs;
_lastLineCounter = 0;
}
}
};

DBLogger.error = function () {
var args = Array.prototype.slice.call(arguments);
Expand Down

0 comments on commit cb56df3

Please sign in to comment.