Created
January 15, 2020 21:18
-
-
Save johnfischelli/5a409be27d74f9ca27879f4b1d65313f to your computer and use it in GitHub Desktop.
Redirect Call to Automated Voicemail Message
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
import RedirectCall from './RedirectCall'; | |
... | |
init(flex, manager) { | |
flex.CallCanvasActions.Content.add( | |
<RedirectCall key="redirect-call-button" /> | |
); | |
} |
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
import React from 'react'; | |
import { IconButton, withTheme } from '@twilio/flex-ui'; | |
const containerStyles = { | |
padding: '20px' | |
} | |
const paragraphStyles = { | |
marginBottom: '20px' | |
} | |
class RedirectButton extends React.Component { | |
onClick() { | |
const customerCallSid = this.props.task.attributes.conference.participants.customer; | |
// invoke a Twilio Function with the customerCallSid | |
// the twilio function will use the REST API to update the call and redirect it to some twiml that play the message | |
} | |
render() { | |
return ( | |
<div style={containerStyles}> | |
<IconButton icon="VoiceBold" themeOverride={this.props.theme.CallCanvas.Button} onClick={ this.onClick.bind(this) }>Play automated voicemail</IconButton> | |
</div> | |
) | |
} | |
} | |
export default withTheme(RedirectButton) |
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
exports.handler = function(context, event, callback) { | |
let client = context.getTwilioClient(), | |
twiml = new Twilio.twiml.VoiceResponse(), | |
customerCallSid = event.CustomerCallSid || null; | |
// Set CORS to allow Flex to make request to a different domain | |
const response = new Twilio.Response(); | |
response.appendHeader("Access-Control-Allow-Origin", "*"); | |
response.appendHeader("Access-Control-Allow-Methods", "OPTIONS POST"); | |
response.appendHeader("Content-Type", "application/json"); | |
response.appendHeader("Access-Control-Allow-Headers", "Content-Type"); | |
// update the customer's call to point to some TwiML | |
client.calls(customerCallSid) | |
.update({ | |
method: "POST", | |
url: `SOME_TWIML_URL` | |
}) | |
.then(call => { | |
response.setBody("complete"); | |
callback(null, response); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment