简体   繁体   中英

Parsing twilio transcription GET request within studio flow?

EDIT: My question is similar to Twilio - Studio - HTTP Request except that the response I get is in xml rather than JSON. So is there a way i can specify a particular xml tag using liquid?

I have designed a studio flow which is as follows

  1. On Incoming call:
  2. Plays message telling caller to leave a voicemail
  3. Records voicemail
  4. Upon hangup, retrieves the transcription of the voicemail using the 'Make HTTP Request' widget using "GET https://user:pass@api.twilio.com/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/ "
  5. Sends that response to a phone number via SMS by putting "{{widget.http_request.body}}" in the message box of the "send_message" widget.

Now I'm so close to that goal however I am having trouble on step 4. I need the response to be turned into just the tag within the xml response. Instead I get the entirety of it which looks like this:

<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
    <Transcriptions end="0" firstpageuri="/2010-04-01/Accounts/AC8275ec8e6fb8c37d6b2a5eca99f0dae6/Recordings/RE1595c7b8bc2b8850401ba44fba0dd24d/Transcriptions?PageSize=50&amp;Page=0" nextpageuri="" page="0" pagesize="50" previouspageuri="" start="0" uri="/2010-04-01/Accounts/AC8275ec8e6fb8c37d6b2a5eca99f0dae6/Recordings/RE1595c7b8bc2b8850401ba44fba0dd24d/Transcriptions?PageSize=50&amp;Page=0">
        <Transcription>
            <Sid>TRbcdfd8fb2fe226ed741b14a05a46cfef</Sid>
            <DateCreated>Wed, 17 Aug 2022 19:27:18 +0000</DateCreated>
            <DateUpdated>Wed, 17 Aug 2022 19:27:42 +0000</DateUpdated> 
            <AccountSid>AC8275ec8e6fb8c37d6b2a5eca99f0dae6</AccountSid> 
            <Status>completed</Status><Type>fast</Type> 
            <RecordingSid>RE1595c7b8bc2b8850401ba44fba0dd24d</RecordingSid> 
            <Duration>7</Duration>
            <TranscriptionText>Hello. Hello, Hello, Hello, Hello. Hello.</TranscriptionText>
            <ApiVersion>2010-04-01</ApiVersion>
            <Price/>
            <PriceUnit>USD</PriceUnit>
            <Uri>/2010-04-01/Accounts/AC8275ec8e6fb8c37d6b2a5eca99f0dae6/Transcriptions/TRbcdfd8fb2fe226ed741b14a05a46cfef</Uri>
        </Transcription>
    </Transcriptions>
</TwilioResponse>

As you can see, I only need the content between the "TranscriptionText" tags, but currently my HTTP_Request widget returns all of the above. How can I do this within studio? I am trying to keep everything contained in Twilio so any solutions involving outside servers are not desired.

Thank you!

Try adding.json to the end, like below, to get a JSON response Studio can parse.

/2010-04-01/Accounts/{YourAccountSid}/Recordings/{RecordingSid}/Transcriptions.json

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