-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c2768bf
Showing
8 changed files
with
1,126 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
exports.handler = function(context, event, callback) { | ||
const topic = event.topic; | ||
const channelSid = event.channelSid; | ||
const expertList = []; | ||
|
||
const axios = require('axios'); | ||
axios.get('https://iris-bobcat-6430.twil.io/experts/list', { | ||
service: 'IS9115e5981568c4e980c1711e0b691dde' | ||
}) | ||
.then(response => { | ||
const data = JSON.parse(response.data); | ||
|
||
response.forEach(expert => { | ||
if (expert.topics.find(topic) !== undefined) { | ||
|
||
context.getTwilioClient().chat.services(context.TWILIO_EXPERT_CHAT_SID) | ||
.channels(channelSid) | ||
.members | ||
.create({identity: expert.name}) | ||
.then(member => console.log(member.sid)) | ||
.catch(error => callback(error)); | ||
|
||
} | ||
}) | ||
}) | ||
.catch(error => callback(error)); | ||
|
||
console.log(expertList); | ||
callback(null, expertList); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
exports.handler = function(context, event, callback) { | ||
|
||
const keywords = event.keywords; | ||
|
||
let originalTopics = []; | ||
if (keywords.search(',') >= 0) { | ||
originalTopics = keywords.split(',').filter(e => e !== ''); | ||
} else if (keywords.search(' ') >= 0) { | ||
originalTopics = keywords.split(' ').filter(e => e !== ''); | ||
} else { | ||
originalTopics.push(keywords.trim()); | ||
} | ||
|
||
console.log(originalTopics); | ||
|
||
processAllTopics(context.getTwilioClient(), originalTopics) | ||
.then(processedTopics => { | ||
console.log('processedTopics:' + processedTopics) | ||
callback(null, processedTopics); | ||
}); | ||
|
||
}; | ||
|
||
const getTaskName = (client, topic) => { | ||
let taskName = client.autopilot.assistants(context.TWILIO_AUTOPILOT_ASSISTANT_SID) | ||
.queries | ||
.create({ language: 'en-US', query: topic.trim() }) | ||
.then(query => { | ||
return query.results.task; | ||
}); | ||
return Promise.resolve(taskName); | ||
}; | ||
|
||
function processTopic(client, topic) { | ||
return Promise.resolve(getTaskName(client, topic)); | ||
} | ||
|
||
function processAllTopics(client, originalTopics) { | ||
return Promise.all(originalTopics.map(topic => processTopic(client, topic))); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
exports.handler = function(context, event, callback) { | ||
|
||
//Build expert json | ||
var payload = { | ||
name: event.name, | ||
number: event.number, | ||
topics: event.topics | ||
}; | ||
|
||
console.log(payload); | ||
|
||
//Submit to expert hub API | ||
const axios = require('axios'); | ||
|
||
axios.post('https://iris-bobcat-6430.twil.io/experts/add', { | ||
service: 'IS9115e5981568c4e980c1711e0b691dde', | ||
expert: JSON.stringify(payload) | ||
}) | ||
.then(response => { | ||
callback(event.topics); | ||
}) | ||
.catch(error => { | ||
callback(error); | ||
}); | ||
|
||
}; | ||
|
Oops, something went wrong.