Last active
March 17, 2016 05:14
-
-
Save stephenkeep/b52177d74457bd9ff7b8 to your computer and use it in GitHub Desktop.
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
[{"id":"96982482.6967d8","type":"subflow","name":"Obtain Action","info":"","in":[{"x":210,"y":69,"wires":[{"id":"6a2b6833.95d498"}]}],"out":[{"x":751,"y":66,"wires":[{"id":"449fa60a.f05c58","port":0},{"id":"6a2b6833.95d498","port":1}]}]},{"id":"449fa60a.f05c58","type":"function","z":"96982482.6967d8","name":"Obtain Action","func":"const table_data = global.get('configMap') || [];\n\nvar found_entities=[];\n\nvar reduced = table_data.filter(function(elem){\n var msg_entities = {};\n var msg_newEntities = false;\n if ( elem.entities !== false ) {\n //Check if the payload contains this entity\n var entities = Object.keys(msg.payload.outcomes[0].entities);\n var stateEntities = Object.keys(msg.chatstate.entities);\n //For each entity request by the config data\n for ( var i=0;i<elem.entities.length;i++ ) {\n //In the case the entity is missing\n if ( entities.indexOf(elem.entities[i]) !== -1 ) {\n //The row is not valid\n msg_newEntities = true;\n msg_entities[elem.entities[i]] = msg.payload.outcomes[0].entities[elem.entities[i]][0].value;\n } else if (stateEntities.indexOf(elem.entities[i]) !== -1){\n msg_entities[elem.entities[i]] = msg.chatstate.entities[elem.entities[i]];\n } else {\n return false;\n }\n }\n }\n if ( elem.status !== false ) {\n if ( elem.status !== msg.chatstate.name ) {\n return false;\n }\n }\n //Check if the message contain the correct intent\n if ( elem.intent !== false ) {\n var contains = false;\n if ( !msg.payload.outcomes.length ) {\n return false;\n }\n if ( Array.isArray(elem.intent ) ) {\n if ( ~elem.intent.indexOf(msg.payload.outcomes[0].intent) ) {\n contains = true;\n }\n } else {\n if ( elem.intent === msg.payload.outcomes[0].intent ) {\n contains = true;\n }\n }\n if ( !contains ) {\n return false;\n }\n \n }\n found_entities.push([msg_newEntities,msg_entities]);\n return true;\n});\nif ( reduced.length ) {\n msg.reduced = reduced[0];\n msg.actions = [].concat(reduced[0].set_action);\n msg.updateDB = found_entities[0][0];\n if ( reduced[0].set_status ) {\n msg.updateDB = true;\n msg.chatstate.name = reduced[0].set_status;\n }\n msg.payload = {\n action : msg.actions.shift(),\n entities : found_entities[0][1],\n message : msg.originalMessage.text\n };\n if ( reduced.length > 1 ) {\n msg.fallback = [reduced[1],found_entities[1]];\n }\n} else {\n msg.payload = {\n action : 'not_found',\n message : msg.originalMessage.text\n };\n}\nreturn msg;","outputs":1,"noerr":0,"x":593,"y":46,"wires":[[]]},{"id":"6a2b6833.95d498","type":"function","z":"96982482.6967d8","name":"Check if emoji π || π","func":"\nif (msg.originalMessage.text === 'π') {\n \n msg.payload = {\n action : 'confirm_praise',\n message : msg.originalMessage.text\n };\n \n return [null, msg];\n} else if (msg.originalMessage.text === 'π') {\n msg.payload = {\n action : 'confirm_negative',\n message : msg.originalMessage.text\n };\n return [null, msg];\n}\n\nreturn [msg, null];","outputs":"2","noerr":0,"x":370.5,"y":110,"wires":[["449fa60a.f05c58"],["24f48eb0.db0b72"]]},{"id":"24f48eb0.db0b72","type":"function","z":"96982482.6967d8","name":"Sort Feedback","func":"if (msg.originalMessage.text === 'π') {\n \n return [msg, null];\n} else if (msg.originalMessage.text === 'π') {\n \n return [null, msg];\n}\nreturn msg;","outputs":"2","noerr":0,"x":589.5,"y":192,"wires":[["c72af92c.38d508"],["1a364389.e5c9bc"]]},{"id":"c72af92c.38d508","type":"create-event","z":"96982482.6967d8","event":"positive","KEEN_PROJECT_ID":"56ea294b59949a4ab87d2a75","KEEN_WRITE_KEY":"264b802f95a76a342c2297959fb38eebba9bdf18d49f05123caa2ea54d31e30292c0499dec5a5e87582d78615a115314ce0ffcafd042abe601a594a274ac99eb10c8be5ab295a18f183b726aff6181bd6c472c1e69b67aa902dfe1cd28ebaeb3","APP_NAME":"techsprint-app","name":"positive feedback","x":814,"y":157,"wires":[]},{"id":"1a364389.e5c9bc","type":"create-event","z":"96982482.6967d8","event":"negative","KEEN_PROJECT_ID":"56ea294b59949a4ab87d2a75","KEEN_WRITE_KEY":"264b802f95a76a342c2297959fb38eebba9bdf18d49f05123caa2ea54d31e30292c0499dec5a5e87582d78615a115314ce0ffcafd042abe601a594a274ac99eb10c8be5ab295a18f183b726aff6181bd6c472c1e69b67aa902dfe1cd28ebaeb3","APP_NAME":"techsprint-app","name":"negative feedback","x":816,"y":221,"wires":[]},{"id":"6f105f42.90efa","type":"subflow","name":"Get Intent","info":"","in":[{"x":940,"y":100,"wires":[{"id":"dd63f223.30e02"}]}],"out":[{"x":1200,"y":100,"wires":[{"id":"dd63f223.30e02","port":0}]}]},{"id":"dd63f223.30e02","type":"wit.ai","z":"6f105f42.90efa","name":"AI","access_token":"LI522TWUS3ST6RNWMBLM3QOIKQCNGLSY","version":"20160316","x":1070,"y":100,"wires":[[]]},{"id":"492c1df6.df3374","type":"cloudant","z":"","host":"redant.cloudant.com","name":"RedAnt"},{"id":"e6029daa.aad9a","type":"subflow","name":"Update DB ( status + entities )","info":"","in":[{"x":60,"y":60,"wires":[{"id":"97089457.877338"}]}],"out":[]},{"id":"5ae69e9f.11df5","type":"function","z":"e6029daa.aad9a","name":"Update DB","func":"if ( msg.payload.status ) {\n msg.chatstate.name = msg.payload.status;\n}\nif ( !msg.chatstate.entities ) {\n msg.chatstate.entities = {};\n}\nfor ( var entity in msg.payload.entities ) {\n msg.chatstate.entities[entity] = msg.payload.entities[entity];\n}\nmsg.payload = msg.chatstate;\nmsg.payload._id = \"\"+msg.chatId;\nreturn msg;","outputs":"1","noerr":0,"x":210,"y":60,"wires":[["8297a5fd.86a948"]]},{"id":"a56b8f37.aebbe","type":"debug","z":"e6029daa.aad9a","name":"","active":true,"console":"false","complete":"true","x":370,"y":80,"wires":[]},{"id":"9caf7ca8.e79a","type":"cloudant out","z":"e6029daa.aad9a","service":"_ext_","cloudant":"492c1df6.df3374","name":"","database":"techsprint1","payonly":true,"operation":"insert","x":710,"y":40,"wires":[["cbfc5f5a.90ce4"]]},{"id":"97089457.877338","type":"function","z":"e6029daa.aad9a","name":"Update DB","func":"if ( !msg.chatstate.entities ) {\n msg.chatstate.entities = {};\n}\nfor ( var entity in msg.payload.entities ) {\n msg.chatstate.entities[entity] = msg.payload.entities[entity];\n}\nmsg.updateTimestamp = Date.now();\nmsg.payload = \"\"+msg.chatId;\nreturn msg;","outputs":"1","noerr":0,"x":210,"y":60,"wires":[["8297a5fd.86a948","3e916434.c0d13c","ae000b7.62f28f8"]]},{"id":"8297a5fd.86a948","type":"debug","z":"e6029daa.aad9a","name":"","active":true,"console":"false","complete":"true","x":370,"y":80,"wires":[]},{"id":"ae000b7.62f28f8","type":"function","z":"e6029daa.aad9a","name":"Update Customer Id","func":"if ( msg.chatstate.entities && msg.chatstate.entities.track_id ) {\n msg.payload = {\n _id : msg.chatstate.entities.track_id,\n customer_id : msg.chatId\n }\n return msg;\n}","outputs":1,"noerr":0,"x":420,"y":120,"wires":[["3ba3c154.35f58e"]]},{"id":"3ba3c154.35f58e","type":"cloudant out","z":"e6029daa.aad9a","service":"_ext_","cloudant":"492c1df6.df3374","name":"","database":"techsprint1","payonly":true,"operation":"insert","x":630,"y":120,"wires":[[]]},{"id":"3e916434.c0d13c","type":"cloudant in","z":"e6029daa.aad9a","service":"_ext_","cloudant":"492c1df6.df3374","name":"","database":"techsprint1","search":"_id_","design":"","index":"","x":390,"y":40,"wires":[["e698e823.667328"]]},{"id":"e698e823.667328","type":"function","z":"e6029daa.aad9a","name":"","func":"if ( msg.payload ) {\n msg.chatstate._rev = msg.payload._rev;\n}\nmsg.payload = msg.chatstate;\nmsg.payload._id = \"\"+msg.chatId;\nif ( msg.updateTimestamp > (msg.chatstate.lastUpdate || 0) ) {\n msg.chatstate.lastUpdate = msg.updateTimestamp;\n return msg;\n}","outputs":1,"noerr":0,"x":550,"y":40,"wires":[["9caf7ca8.e79a","be611576.581818"]]},{"id":"be611576.581818","type":"debug","z":"e6029daa.aad9a","name":"","active":true,"console":"false","complete":"false","x":730,"y":80,"wires":[]},{"id":"cbfc5f5a.90ce4","type":"debug","z":"e6029daa.aad9a","name":"","active":true,"console":"false","complete":"false","x":890,"y":40,"wires":[]},{"id":"492c1df6.df3374","type":"cloudant","z":"","host":"redant.cloudant.com","name":"RedAnt"},{"id":"e06dedaa.61fc4","type":"onthedot-connection","z":"","name":"TechSprint1","api_url":"https://sbapi.onthedot.com/api/v1.0","api_key":"1dOHtajAxKpCP0kLnc6BKMI6ZeQa"},{"id":"a5cd22d1.f5878","type":"subflow","name":"Obtain track details","info":"","in":[{"x":80,"y":60,"wires":[{"id":"d622fa85.399a88"}]}],"out":[{"x":760,"y":60,"wires":[{"id":"12ad7935.a39ab7","port":0}]}]},{"id":"d622fa85.399a88","type":"function","z":"a5cd22d1.f5878","name":"Configure search","func":"var track_id = msg.payload.entities.track_id;\nmsg.tracking_id = track_id;\nmsg.payload = {\n store_id : 'RedAnt-01',\n order_id : track_id\n}\nreturn msg;","outputs":1,"noerr":0,"x":230,"y":60,"wires":[["a39daaa8.f9ac88"]]},{"id":"a39daaa8.f9ac88","type":"onthedot-booking","z":"a5cd22d1.f5878","creds":"e06dedaa.61fc4","name":"","uuid":"","booking":{},"x":420,"y":60,"wires":[["12ad7935.a39ab7"]]},{"id":"12ad7935.a39ab7","type":"function","z":"a5cd22d1.f5878","name":"Check response","func":"function formatHour(hour) {\n if (hour > 12) {\n return hour - 12 + 'pm';\n } else {\n return hour + 'am';\n }\n }\n \n\nif ( msg.payload ) {\n msg.payload = msg.payload.data;\n console.log(msg.payload.data);\n var startDate = new Date(msg.payload.data.timeslot.startTime);\n var endDate = new Date(msg.payload.data.timeslot.endTime);\n \n var startHour = formatHour(startDate.getHours());\n var endHour = formatHour(endDate.getHours());\n \n msg.timeslot = startHour + ' - ' + endHour;\n msg.date = startDate.toJSON().slice(0,10).split('-').reverse().join('/');\n msg.packageStatus = msg.payload.data.status;\n msg.packageLocation = {\n lat : 51.5233512,\n lng : -0.08101320000002943\n }\n msg.driverName = 'Stephen';\n msg.driverMake = 'Fiat';\n msg.driverModel= 'Multipla';\n msg.driverReg = 'AA12 1AB';\n msg.timeDistance = '10';\n msg.payload = {\n message : 'confirm_tracking_id'\n };\n} else {\n msg.payload = {\n message : ['confirm_tracking_id','I can\\'t track the package']\n };\n msg.fallback = false;\n msg.continue = false;\n}\nreturn msg;","outputs":"1","noerr":0,"x":620,"y":60,"wires":[[]]},{"id":"c4d8ce16.4104f","type":"subflow","name":"Track Package","info":"","in":[{"x":64,"y":149,"wires":[{"id":"6b0f606.54264a"},{"id":"9f4f4a22.a253a8"}]}],"out":[{"x":880,"y":140,"wires":[{"id":"7d25c0dc.de4c5","port":0},{"id":"36885358.886ddc","port":0},{"id":"d31697a3.b67358","port":0}]}]},{"id":"6b0f606.54264a","type":"switch","z":"c4d8ce16.4104f","name":"","property":"packageStatus","propertyType":"msg","rules":[{"t":"eq","v":"Booked","vt":"str"},{"t":"eq","v":"Driver at the Store","vt":"str"},{"t":"eq","v":"Parcels Collected","vt":"str"},{"t":"eq","v":"Driver at the Delivery","vt":"str"},{"t":"eq","v":"Delivered","vt":"str"},{"t":"else"}],"checkall":"true","outputs":6,"x":174,"y":149,"wires":[["7d25c0dc.de4c5"],["d31697a3.b67358"],["d31697a3.b67358"],["d31697a3.b67358"],["36885358.886ddc"],["d31697a3.b67358"]]},{"id":"7d25c0dc.de4c5","type":"function","z":"c4d8ce16.4104f","name":"Booked","func":"msg.payload = \n {\n message : 'give_delivery_location_not_out_yet'\n }\nreturn msg;","outputs":1,"noerr":0,"x":424,"y":89,"wires":[[]]},{"id":"36885358.886ddc","type":"function","z":"c4d8ce16.4104f","name":"Delivered","func":"msg.payload = {\n message : 'deliver'\n}\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":200,"wires":[[]]},{"id":"9f4f4a22.a253a8","type":"debug","z":"c4d8ce16.4104f","name":"","active":true,"console":"false","complete":"true","x":170,"y":220,"wires":[]},{"id":"d31697a3.b67358","type":"function","z":"c4d8ce16.4104f","name":"Driver at the Store / Parcels Collected / Driver at the Delivery","func":"msg.payload = {\n message : ['give_delivery_location_out_for_delivery',`%loc[${msg.packageLocation.lat}:${msg.packageLocation.lng}]`]\n}\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":140,"wires":[[]]},{"id":"b58e935c.c6272","type":"subflow","name":"Execute Action","info":"","in":[{"x":40,"y":180,"wires":[{"id":"f9b82a24.0c9c68"},{"id":"d99b61c7.01a6b"}]}],"out":[{"x":1020,"y":300,"wires":[{"id":"4c849cc5.2f1e94","port":0},{"id":"d10f7fa0.04855","port":0},{"id":"a7433f5e.071f7","port":0},{"id":"f7b3c17c.0c2e8","port":0},{"id":"c0cc89b7.48e548","port":0},{"id":"8f9dffbc.8f72a","port":0},{"id":"41f7acd8.a30cc4","port":0},{"id":"ecf6ac67.7ee84","port":0},{"id":"92d62058.5ad0d","port":0},{"id":"63034e25.2a0b7","port":0},{"id":"f91b49af.08c9e8","port":0},{"id":"68a19554.e9c92c","port":0},{"id":"dc8c795f.050038","port":0},{"id":"c430a091.fd93c","port":0},{"id":"fe4f5a64.3d9178","port":0},{"id":"ef2ef88e.fbfb68","port":0},{"id":"df0ea90d.7fa7c8","port":0},{"id":"c32ca0c1.1d2fe","port":0},{"id":"d7e3d766.3a43e8","port":0},{"id":"48d6489b.4364e8","port":0},{"id":"a5052a03.5afad8","port":0}]}]},{"id":"d99b61c7.01a6b","type":"switch","z":"b58e935c.c6272","name":"","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"not_found","vt":"str"},{"t":"eq","v":"check_track_id","vt":"str"},{"t":"eq","v":"track_package","vt":"str"},{"t":"eq","v":"ask_track_id","vt":"str"},{"t":"eq","v":"track_slot","vt":"str"},{"t":"eq","v":"check_delivered","vt":"str"},{"t":"eq","v":"say_hello","vt":"str"},{"t":"eq","v":"say_goodbye","vt":"str"},{"t":"eq","v":"obtain_complain","vt":"str"},{"t":"eq","v":"make_complain","vt":"str"},{"t":"eq","v":"need_to_be_delivered","vt":"str"},{"t":"eq","v":"obtain_track_details","vt":"str"},{"t":"eq","v":"need_to_be_delivered","vt":"str"},{"t":"eq","v":"reset","vt":"str"},{"t":"eq","v":"check_phone_number","vt":"str"},{"t":"eq","v":"make_call","vt":"str"},{"t":"eq","v":"ask_phone_number","vt":"str"},{"t":"eq","v":"check_driver","vt":"str"},{"t":"eq","v":"cancel_package","vt":"str"},{"t":"eq","v":"confirm_praise","vt":"str"},{"t":"eq","v":"confirm_negative","vt":"str"}],"checkall":"true","outputs":21,"x":370,"y":371,"wires":[["d10f7fa0.04855"],["c430a091.fd93c"],["4c849cc5.2f1e94"],["dc8c795f.050038"],["63034e25.2a0b7"],["92d62058.5ad0d"],["68a19554.e9c92c"],["a7433f5e.071f7"],["f7b3c17c.0c2e8"],["c0cc89b7.48e548"],["8f9dffbc.8f72a"],["ecf6ac67.7ee84"],["41f7acd8.a30cc4"],["f91b49af.08c9e8"],["fe4f5a64.3d9178"],["ef2ef88e.fbfb68"],["df0ea90d.7fa7c8"],["c32ca0c1.1d2fe"],["d7e3d766.3a43e8"],["48d6489b.4364e8"],["a5052a03.5afad8"]]},{"id":"4c849cc5.2f1e94","type":"subflow:c4d8ce16.4104f","z":"b58e935c.c6272","name":"","x":620,"y":100,"wires":[[]]},{"id":"f9b82a24.0c9c68","type":"debug","z":"b58e935c.c6272","name":"","active":true,"console":"false","complete":"false","x":170,"y":220,"wires":[]},{"id":"d10f7fa0.04855","type":"function","z":"b58e935c.c6272","name":"Can't understand","func":"\n// msg.payload = {\n// message : 'dont_understand'\n// }\n\n// msg.continue = false;\n// return msg;\n\nmsg.payload = {\n message : 'dont_understand'\n};\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":20,"wires":[[]]},{"id":"68a19554.e9c92c","type":"function","z":"b58e935c.c6272","name":"Say Hello","func":"msg.payload = {\n message : 'starting'\n};\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":260,"wires":[[]]},{"id":"a7433f5e.071f7","type":"function","z":"b58e935c.c6272","name":"Say Goodbye","func":"msg.payload = {\n message : 'ending'\n};\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":300,"wires":[[]]},{"id":"f7b3c17c.0c2e8","type":"function","z":"b58e935c.c6272","name":"Obtain complain","func":"msg.payload = {\n message : 'ask_for_complaint'\n}\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":340,"wires":[[]]},{"id":"c0cc89b7.48e548","type":"function","z":"b58e935c.c6272","name":"Make complain","func":"msg.payload = {\n message : 'confirm_complaint'\n}\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":380,"wires":[[]]},{"id":"8f9dffbc.8f72a","type":"function","z":"b58e935c.c6272","name":"Need to be delivered","func":"\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":420,"wires":[[]]},{"id":"41f7acd8.a30cc4","type":"function","z":"b58e935c.c6272","name":"Need to be delivered","func":"if ( msg.packageStatus === 'Delivered' ) {\n msg.payload = {};\n} else {\n \n}\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":500,"wires":[[]]},{"id":"ecf6ac67.7ee84","type":"subflow:a5cd22d1.f5878","z":"b58e935c.c6272","name":"","x":640,"y":460,"wires":[[]]},{"id":"92d62058.5ad0d","type":"function","z":"b58e935c.c6272","name":"Check is delivered","func":"msg.payload = {\n message : msg.packageStatus === 'Delivered'\n ? 'deliver'\n : ( msg.packageStatus === 'Driver at the Delivery'\n ? 'give_delivery_location_out_for_delivery'\n : 'give_delivery_location_not_out_yet')\n}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":220,"wires":[[]]},{"id":"63034e25.2a0b7","type":"function","z":"b58e935c.c6272","name":"Check delivery slot","func":"msg.payload = {\n message : 'give_timeslot'\n}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":180,"wires":[[]]},{"id":"f91b49af.08c9e8","type":"function","z":"b58e935c.c6272","name":"Reset","func":"msg.chatstate.entities = {};\nmsg.updateDB = true;\nmsg.payload = {\n message : 'start_again'\n}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":540,"wires":[[]]},{"id":"dc8c795f.050038","type":"function","z":"b58e935c.c6272","name":"Ask track Id","func":"msg.payload = {\n message : 'ask_for_tracking_id'\n}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":140,"wires":[[]]},{"id":"c430a091.fd93c","type":"function","z":"b58e935c.c6272","name":"Check if track id is valid","func":"var orderRegex = /[\\d]{8,}/g;\nif ( orderRegex.test(msg.payload.message) \n && (msg.payload.message.match(orderRegex).length === 1) \n && (msg.payload.message.match(orderRegex)[0].length === 8)) {\n msg.updateDB = true;\n msg.chatstate.entities.track_id = msg.payload.message.match(orderRegex)[0];\n msg.chatstate.status = 'default';\n msg.payload = msg.chatstate;\n return msg;\n}\nmsg.payload = {\n message : 'wrong_track_id',\n status : false\n};\nmsg.continue = false;\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":60,"wires":[[]]},{"id":"fe4f5a64.3d9178","type":"function","z":"b58e935c.c6272","name":"Check phone number","func":"var phoneNumberRegex = /(\\d{5} ?\\d{6})/;\nif ( phoneNumberRegex.test(msg.payload.message) ) {\n msg.updateDB = true;\n msg.chatstate.entities.phone_number = msg.payload.message.match(phoneNumberRegex)[0].split(' ').join('');\n msg.chatstate.status = 'default';\n msg.payload = msg.chatstate;\n return msg;\n}\nmsg.payload = {\n message : 'ask_for_phone_number',\n status : false\n};\nmsg.continue = false;\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":580,"wires":[[]]},{"id":"ef2ef88e.fbfb68","type":"function","z":"b58e935c.c6272","name":"Make call","func":"msg.payload = {\n message : ['pass_to_human',`%call[${msg.chatstate.entities.phone_number}]`]\n}\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":620,"wires":[[]]},{"id":"df0ea90d.7fa7c8","type":"function","z":"b58e935c.c6272","name":"Ask phone number","func":"msg.payload = {\n message : 'ask_for_phone_number',\n status : false\n};\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":660,"wires":[[]]},{"id":"c32ca0c1.1d2fe","type":"function","z":"b58e935c.c6272","name":"Check driver","func":"msg.payload = {\n message : 'driver_details'\n}\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":700,"wires":[[]]},{"id":"d7e3d766.3a43e8","type":"function","z":"b58e935c.c6272","name":"Cancel Package","func":"msg.payload = {\n message : msg.packageStatus === 'Delivered'\n ? 'cant_change'\n : 'cancelled'\n}\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":740,"wires":[[]]},{"id":"f1ea138d.ace44","type":"function","z":"b58e935c.c6272","name":"Can Change slot","func":"if ( msg.packageStatus === 'Delivered' ) {\n msg.payload = {\n message :'cant_change'\n }\n msg.continue = false;\n}\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":780,"wires":[[]]},{"id":"48d6489b.4364e8","type":"function","z":"b58e935c.c6272","name":"Thank for Feedback","func":"msg.payload = {\n message : 'confirm_praise'\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":821,"wires":[[]]},{"id":"a5052a03.5afad8","type":"function","z":"b58e935c.c6272","name":"Apologise for Poor Service","func":"msg.payload = {\n message : 'confirm_negative'\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":637,"y":863,"wires":[[]]},{"id":"41c7e778.52b8b8","type":"twilio-connection","z":"94496328.f50fa","name":"Red Ant","api_sid":"AC08acacf831614258d5421508c6c2879e","api_token":"502082abaceb7ecc95937ddb054454b2"},{"id":"e7616ef2.51128","type":"telegram bot","z":"","botname":"DotCustomerBot","usernames":"[]","chatids":"[]"},{"id":"94496328.f50fa","type":"subflow","name":"Send to telegram","info":"","in":[{"x":40,"y":140,"wires":[{"id":"c031e63e.29a9e8"}]}],"out":[{"x":740,"y":140,"wires":[{"id":"c4a378f6.783488","port":0}]}]},{"id":"c4a378f6.783488","type":"telegram sender","z":"94496328.f50fa","name":"","bot":"e7616ef2.51128","x":590,"y":140,"wires":[[]]},{"id":"f10ad9b4.88d468","type":"function","z":"94496328.f50fa","name":"","func":"msg.payload = {\n content : msg.payload,\n chatId : msg.chatId,\n type : msg.msgType\n};\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":140,"wires":[["c4a378f6.783488"]]},{"id":"a7e928ca.79e608","type":"template-2.0","z":"94496328.f50fa","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"This is the payload: {{payload}} !","x":270,"y":100,"wires":[["f10ad9b4.88d468"]]},{"id":"c031e63e.29a9e8","type":"function","z":"94496328.f50fa","name":"","func":"if ( msg.payload.indexOf('%loc') === 0 ) {\n msg.msgType = 'location';\n var lat,lng;\n msg.payload = msg.payload.slice(5,-1).split(':');\n msg.payload = {\n latitude : msg.payload[0],\n longitude: msg.payload[1]\n }\n return [null,msg,null];\n}\nif ( msg.payload.indexOf('%call') === 0 ) {\n msg.payload = {\n to : msg.payload.slice(6,-1)\n };\n return [null,null,msg];\n}\nmsg.template = msg.payload;\nmsg.msgType = 'message';\nreturn [msg,null,null];","outputs":"3","noerr":0,"x":150,"y":140,"wires":[["a7e928ca.79e608"],["f10ad9b4.88d468"],["5448b87f.e6ff08","d6a21c44.0a1be"]]},{"id":"5448b87f.e6ff08","type":"twilio-call","z":"94496328.f50fa","creds":"41c7e778.52b8b8","name":"","to":"","from":"+441183100401","twilio_url":"https://techsprint2.redconnectapp.io/say","x":290,"y":180,"wires":[[]]},{"id":"d6a21c44.0a1be","type":"debug","z":"94496328.f50fa","name":"","active":true,"console":"false","complete":"false","x":240,"y":280,"wires":[]},{"id":"6a06fb48.335654","type":"subflow","name":"Send Response","info":"","in":[{"x":72,"y":200,"wires":[{"id":"58611a65.39b8f4"}]}],"out":[]},{"id":"58611a65.39b8f4","type":"function","z":"6a06fb48.335654","name":"Iterate over messages","func":"var phrases = global.get('phrases');\nvar returnArray = [];\nfunction checkMessage(m){\n //Check if the first one is 0\n if (m[0] === 'random') {\n //Choose a random one\n return returnArray.push(m.slice(1)[Math.floor(Math.random() * (m.length-1)) ]);\n }\n m.forEach(function(mes){\n if ( phrases[mes] ) {\n return checkMessage([].concat(phrases[mes]));\n }\n returnArray.push(mes);\n });\n}\ncheckMessage(msg.messages);\nmsg.payload = returnArray;\nreturn msg;","outputs":1,"noerr":0,"x":232,"y":200,"wires":[["de418df.5336e7","5309fa70.e47874"]]},{"id":"de418df.5336e7","type":"debug","z":"6a06fb48.335654","name":"","active":true,"console":"true","complete":"true","x":422,"y":340,"wires":[]},{"id":"5309fa70.e47874","type":"Serial Iterator","z":"6a06fb48.335654","name":"","property":"payload","inputFlow":"input","saveOutput":0,"recursive":0,"storeId":1,"x":582,"y":100,"wires":[["2a6a6c79.518174"],[]]},{"id":"2a6a6c79.518174","type":"subflow:94496328.f50fa","z":"6a06fb48.335654","name":"","x":530,"y":220,"wires":[["294b4ddc.6d5b92"]]},{"id":"294b4ddc.6d5b92","type":"delay","z":"6a06fb48.335654","name":"","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1200","randomLast":"1600","randomUnits":"milliseconds","drop":false,"x":700,"y":220,"wires":[["5309fa70.e47874"]]},{"id":"492c1df6.df3374","type":"cloudant","z":"","host":"redant.cloudant.com","name":"RedAnt"},{"id":"af4356af.e9f908","type":"subflow","name":"Obtain status","info":"","in":[{"x":40,"y":60,"wires":[{"id":"27efd4ac.eac7fc"}]}],"out":[{"x":600,"y":40,"wires":[{"id":"3f6c9cd.a0cab64","port":0}]}]},{"id":"e1b9777b.92e148","type":"cloudant in","z":"af4356af.e9f908","service":"_ext_","cloudant":"492c1df6.df3374","name":"","database":"techsprint1","search":"_id_","design":"","index":"","x":310,"y":60,"wires":[["3f6c9cd.a0cab64"]]},{"id":"27efd4ac.eac7fc","type":"function","z":"af4356af.e9f908","name":"Set query","func":"msg.chatId = msg.payload.chatId;\nmsg.oldPayload = msg.payload;\nmsg.payload = {\n _id : \"\"+msg.payload.chatId\n}\nreturn msg;","outputs":1,"noerr":0,"x":160,"y":60,"wires":[["e1b9777b.92e148"]]},{"id":"3f6c9cd.a0cab64","type":"function","z":"af4356af.e9f908","name":"","func":"var _status = {\n name : 'start',\n entities : []\n};\nif ( msg.payload && (msg.payload !== null) && msg.payload.name ) {\n msg.chatstate = msg.payload;\n msg.chatstate._rev = msg.payload._rev;\n} else {\n msg.chatstate = _status;\n}\nmsg.payload = msg.oldPayload;\ndelete msg.oldPayload;\ndelete msg.cloudant;\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":60,"wires":[["4983a613.bd94f8"]]},{"id":"4983a613.bd94f8","type":"debug","z":"af4356af.e9f908","name":"","active":true,"console":"false","complete":"true","x":610,"y":100,"wires":[]},{"id":"e7616ef2.51128","type":"telegram bot","z":"","botname":"DotCustomerBot","usernames":"[]","chatids":"[]"},{"id":"83e4c55a.4c67c8","type":"telegram receiver","z":"a894355.114f0c8","name":"","bot":"e7616ef2.51128","x":290,"y":80,"wires":[["d81518f0.742f98"],["d81518f0.742f98"]]},{"id":"9de3d325.c868b","type":"switch","z":"a894355.114f0c8","name":"","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"message","vt":"str"},{"t":"eq","v":"location","vt":"str"},{"t":"eq","v":"voice","vt":"str"},{"t":"else"}],"checkall":"true","outputs":4,"x":690,"y":80,"wires":[["c793ca3d.8de458"],["cbf22876.ed9138"],["9f0cc15.ce3df4"],["baa0f165.47dbf","99a51afa.12e378"]]},{"id":"cbf22876.ed9138","type":"debug","z":"a894355.114f0c8","name":"","active":true,"console":"false","complete":"false","x":890,"y":180,"wires":[]},{"id":"aab9b468.42bbb8","type":"comment","z":"a894355.114f0c8","name":"Message","info":"","x":880,"y":60,"wires":[]},{"id":"9d6db4ba.75ee48","type":"comment","z":"a894355.114f0c8","name":"Location","info":"","x":880,"y":140,"wires":[]},{"id":"b8e9f0e4.6113e","type":"comment","z":"a894355.114f0c8","name":"Unsupported","info":"","x":890,"y":300,"wires":[]},{"id":"baa0f165.47dbf","type":"debug","z":"a894355.114f0c8","name":"","active":true,"console":"false","complete":"true","x":870,"y":340,"wires":[]},{"id":"8e8894e6.7d1068","type":"telegram sender","z":"a894355.114f0c8","name":"","bot":"e7616ef2.51128","x":1250,"y":380,"wires":[["5a2c90.0156337"]]},{"id":"fd034ad6.4ae578","type":"template","z":"a894355.114f0c8","name":"Unsupported Text","field":"payload.content","fieldType":"msg","format":"text","template":"You can't use this type of messages","x":1050,"y":380,"wires":[["8e8894e6.7d1068"]]},{"id":"5a2c90.0156337","type":"debug","z":"a894355.114f0c8","name":"","active":true,"console":"false","complete":"false","x":1430,"y":380,"wires":[]},{"id":"99a51afa.12e378","type":"template","z":"a894355.114f0c8","name":"Set type","field":"payload.type","fieldType":"msg","format":"text","template":"message","x":880,"y":380,"wires":[["fd034ad6.4ae578"]]},{"id":"1f18eee7.333861","type":"comment","z":"a894355.114f0c8","name":"Voice","info":"","x":870,"y":220,"wires":[]},{"id":"9f0cc15.ce3df4","type":"debug","z":"a894355.114f0c8","name":"","active":true,"console":"false","complete":"false","x":890,"y":260,"wires":[]},{"id":"c793ca3d.8de458","type":"change","z":"a894355.114f0c8","name":"Extract content","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.content","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":98,"wires":[["dd63f223.30e02","1c38f4af.e3c70b"]]},{"id":"d81518f0.742f98","type":"subflow:af4356af.e9f908","z":"a894355.114f0c8","name":"","x":510,"y":80,"wires":[["9de3d325.c868b","3c13bed6.64db02"]]},{"id":"933ef49e.deba18","type":"subflow:6a06fb48.335654","z":"a894355.114f0c8","name":"","x":1680,"y":220,"wires":[]},{"id":"355c5bcb.7dcd84","type":"subflow:b58e935c.c6272","z":"a894355.114f0c8","name":"","x":1418,"y":87,"wires":[["67600d30.16add4"]]},{"id":"cdd73919.e2a498","type":"inject","z":"a894355.114f0c8","name":"Set globals","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":true,"x":200,"y":520,"wires":[["944cbf71.5938d","90273556.e053c8"]]},{"id":"f397b9c3.d7cf98","type":"function","z":"a894355.114f0c8","name":"","func":"if ( msg.payload && msg.payload.data ) {\n global.set('configMap',msg.payload.data.map(function(a){\n if ( a.entities ) {\n a.entities = [].concat(a.entities);\n }\n return a;\n }));\n}\n","outputs":1,"noerr":0,"x":750,"y":540,"wires":[[]]},{"id":"6e030aac.ca8374","type":"cloudant in","z":"a894355.114f0c8","service":"_ext_","cloudant":"492c1df6.df3374","name":"","database":"techsprint1","search":"_id_","design":"","index":"","x":590,"y":540,"wires":[["f397b9c3.d7cf98"]]},{"id":"944cbf71.5938d","type":"function","z":"a894355.114f0c8","name":"get configData","func":"\nreturn {\n payload : {\n _id : 'configData'\n }\n};","outputs":1,"noerr":0,"x":400,"y":540,"wires":[["6e030aac.ca8374"]]},{"id":"5c10d140.086d9","type":"function","z":"a894355.114f0c8","name":"","func":"if ( msg.payload && msg.payload.data ) {\n global.set('phrases',msg.payload.data);\n}\n","outputs":1,"noerr":0,"x":750,"y":500,"wires":[[]]},{"id":"cd2a0f2c.93eab","type":"cloudant in","z":"a894355.114f0c8","service":"_ext_","cloudant":"492c1df6.df3374","name":"","database":"techsprint1","search":"_id_","design":"","index":"","x":590,"y":500,"wires":[["5c10d140.086d9"]]},{"id":"90273556.e053c8","type":"function","z":"a894355.114f0c8","name":"get phrases","func":"\nreturn {\n payload : {\n _id : 'phrases'\n }\n};","outputs":1,"noerr":0,"x":390,"y":500,"wires":[["cd2a0f2c.93eab"]]},{"id":"67600d30.16add4","type":"function","z":"a894355.114f0c8","name":"Execute Next Action","func":"if ( msg.payload.message ) {\n //Collect the messages\n if ( ! msg.messages ) {\n msg.messages = [];\n }\n msg.messages = msg.messages.concat(msg.payload.message);\n}\nif ( msg.continue === false ) {\n return [null,msg];\n}\nif ( msg.actions && msg.actions.length ) {\n msg.payload.action = msg.actions.shift();\n return [msg,null];\n}\nreturn [null,msg];","outputs":"2","noerr":0,"x":1420,"y":160,"wires":[["355c5bcb.7dcd84"],["c68516d1.a7d818","6c9b84b7.21c30c","933ef49e.deba18"]]},{"id":"a0c67987.bf5588","type":"subflow:e6029daa.aad9a","z":"a894355.114f0c8","x":1950,"y":160,"wires":[]},{"id":"3c13bed6.64db02","type":"function","z":"a894355.114f0c8","name":"Check if is first message","func":"if ( msg.chatstate.name === 'start' ) {\n return {\n payload : {\n message : 'starting'\n },\n chatId : msg.chatId\n };\n \n}","outputs":1,"noerr":0,"x":410,"y":160,"wires":[["bd412652.13bbc8"]]},{"id":"c68516d1.a7d818","type":"function","z":"a894355.114f0c8","name":"Requesting Update","func":"if ( msg.updateDB ) {\n return msg;\n}","outputs":1,"noerr":0,"x":1690,"y":160,"wires":[["a0c67987.bf5588"]]},{"id":"bd412652.13bbc8","type":"subflow:6a06fb48.335654","z":"a894355.114f0c8","x":620,"y":160,"wires":[]},{"id":"6c9b84b7.21c30c","type":"debug","z":"a894355.114f0c8","name":"","active":true,"console":"false","complete":"messages","x":1640,"y":300,"wires":[]},{"id":"1c38f4af.e3c70b","type":"subflow:6f105f42.90efa","z":"a894355.114f0c8","x":1066,"y":98,"wires":[["e4843a66.1b7bc8"]]},{"id":"e4843a66.1b7bc8","type":"subflow:96982482.6967d8","z":"a894355.114f0c8","name":"","x":1233,"y":98,"wires":[["355c5bcb.7dcd84"]]}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment