-
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.
feat: added guided way to create outbound call
- Loading branch information
Showing
6 changed files
with
136 additions
and
4 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,70 @@ | ||
import prompt from "prompts"; | ||
import { ILocalConfig, loadJsonFile } from "../lib"; | ||
import API from "../lib/api"; | ||
import { PhoneNumberUtil } from "google-libphonenumber"; | ||
|
||
/** | ||
* | ||
*/ | ||
export default async (_, options: any ) => { | ||
const config = loadJsonFile(options.configFile) as ILocalConfig; | ||
const api = new API(config, options.AU); | ||
|
||
const phones = await api.getRemotePhones(); | ||
|
||
const { from } = await prompt({ | ||
type: 'select', | ||
name: 'from', | ||
message: 'Caller', | ||
choices: phones.map(({ number }) => ({ | ||
title: number, | ||
value: number | ||
})), | ||
initial: 0, | ||
}); | ||
|
||
const { to } = await prompt({ | ||
type: 'text', | ||
name: 'to', | ||
message: 'Callee. Must contain the country code', | ||
initial: '+1234567890', | ||
validate: (value: string) => { | ||
try { | ||
const phoneUtil = PhoneNumberUtil.getInstance(); | ||
|
||
if(phoneUtil.isValidNumber( | ||
phoneUtil.parse(value.trim().replace(' ', '')) | ||
)) { | ||
return true; | ||
} | ||
} catch(e) {} | ||
|
||
return 'Invalid phone number'; | ||
} | ||
}); | ||
|
||
const { tag } = await prompt({ | ||
type: 'text', | ||
name: 'tag', | ||
message: 'JSON data to send to bot when call initiates', | ||
initial: '{"hello": "world"}', | ||
validate: v => { | ||
try { | ||
JSON.parse(v); | ||
} catch(e) { | ||
return 'Please provide valid JSON.'; | ||
} | ||
|
||
return true; | ||
} | ||
}); | ||
|
||
await api.createCall( | ||
from[0] === '+' ? from : `+${from}`, | ||
to[0] === '+' ? to : `+${to}`, | ||
phones.find(o => o.number === from).application_sid, | ||
JSON.parse(tag), | ||
); | ||
|
||
console.log('Done.'); | ||
} |
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