简体   繁体   中英

Twilio PCI Compliant <Gather> in Function Widget with Studio

I've been stalking around here and have gotten most of my answers as I make my way through this new tool, but I'm now stuck and need some direct advice.

The Gather function in Studio is not PCI compliant, so I have to shift my call to a Function and return the parsed data--I finally figured out how to do that one--however, I've found that I cannot call the web service housed within the single function and had to send the with event.Digits to another function to make the web service call to my token provider. This works, however it has led to a strange result: my token is read back as TTS and then the call is hung up. I have no TTS action in play. Below are my sets of code:

Initial function called from Studio:

const got = require('got');

exports.handler = function(context, event, callback) {
    let twiml = new Twilio.twiml.VoiceResponse();

    twiml.gather({
        input: 'dtmf',
        finishOnKey: '#',
        timeout: 10,
        action: 'paymenttest',
        method: 'GET'
    }).say('Enter CC');

    console.log(twiml);
    callback(null, twiml);
};

This successfully calls my function with the digits entered:

const got = require('got');

exports.handler = function(context, event, callback) {
    let twiml = new Twilio.twiml.MessagingResponse();
    const url ='my payment gateway' + event.Digits + '&EXPDATE=1220&CARDTYPE=VI';

    got.get(url, {
        headers: {
            'content-Type': 'application/x-www-form-urlencoded'
        }
    }).then(function(response) {
        // Check the response and ask your second question here
        event.callback(null, response.body);
    }).catch(function(error) {
        // Boo, there was an error.
        callback(error)
    });
};

This successfully returns the token....but as mentioned prior...it's read back out to me instead of getting included in the data returned back to Studio.

Twilio developer evangelist here.

Right now Studio is not well setup for using TwiML from a Twilio Function and then continuing the flow. In your case when you return the token from your second Function Twilio is dealing with it as if you just returned text to a regular TwiML webhook. When this happens Twilio defaults to assuming you meant <Say> and reads out the text.

While the team work on redirecting calls back into Studio flows there is a workaround.

Instead of returning the token in the second Function, return some TwiML that includes a <Redirect> to your Studio flow's webhook URL with ?FlowEvent=audioComplete appended. You will also need to add a dummy Say/Play widget after your Function widget (it becomes the next part in the flow that can trigger an "audio complete" message, so exists to collect that and send on to the next widget).

The only thing that we haven't handled in thie workaround is sending the token to the flow. I don't believe we can do this via this redirect workaround, so instead I'd recommend storing the token in your own database or something like a Twilio Sync object. This way you can use it outside of Studio however you like. If you need it within the Studio flow then you can create one more Function that returns the token as JSON, and that will be stored within the flow variables then.

If you would prefer to use <Pay> , as this would be a lot easier, I also recommend requesting the pay connector you need .

I think philnash answer here got old, even when it still works.

Right now, you should have to call the first function using TwiML Redirect node.

In the second function, you should have to add a redirect to the webhook of the flow adding? FlowEvent=return&foo=bar (where foo=bar should be changed by the info you really want to return).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM