forked from twilio-labs/call-gpt
-
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.
Add call transfer example, make all functions async
- Loading branch information
Showing
12 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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,20 @@ | ||
require('dotenv').config(); | ||
|
||
const transferCall = async function (call) { | ||
|
||
console.log('Transferring call', call.callSid); | ||
const accountSid = process.env.TWILIO_ACCOUNT_SID; | ||
const authToken = process.env.TWILIO_AUTH_TOKEN; | ||
const client = require('twilio')(accountSid, authToken); | ||
|
||
return await client.calls(call.callSid) | ||
.update({twiml: `<Response><Dial>${process.env.TRANSFER_NUMBER}</Dial></Response>`}) | ||
.then(() => { | ||
return 'The call was transferred successfully, say goodbye to the customer.'; | ||
}) | ||
.catch(() => { | ||
return 'The call was not transferred successfully, advise customer to call back later.'; | ||
}); | ||
}; | ||
|
||
module.exports = transferCall; |
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
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
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
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,31 @@ | ||
require('dotenv').config(); | ||
const setTimeout = require('timers/promises').setTimeout; | ||
const transferCall = require('../functions/transferCall'); | ||
|
||
test('Expect transferCall to successfully redirect call', async () => { | ||
|
||
async function makeOutBoundCall() { | ||
const accountSid = process.env.TWILIO_ACCOUNT_SID; | ||
const authToken = process.env.TWILIO_AUTH_TOKEN; | ||
|
||
const client = require('twilio')(accountSid, authToken); | ||
|
||
const sid = await client.calls | ||
.create({ | ||
url: `https://${process.env.SERVER}/incoming`, | ||
to: process.env.YOUR_NUMBER, | ||
from: process.env.FROM_NUMBER | ||
}) | ||
.then(call => call.sid); | ||
|
||
return sid; | ||
} | ||
|
||
const callSid = await makeOutBoundCall(); | ||
console.log(callSid); | ||
await setTimeout(10000); | ||
|
||
const transferResult = await transferCall(callSid); | ||
|
||
expect(transferResult).toBe('The call was transferred successfully'); | ||
}, 20000); |