You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Twilio Studio流中提取语音转写XML的TranscriptionText内容?

如何在Twilio Studio中提取XML响应里的内容

方法一:让API返回JSON(更简便)

Twilio API支持通过请求头指定返回格式,直接让接口返回JSON,避免XML解析的麻烦:

  1. 打开Studio流程中的「Make HTTP Request」组件
  2. 在Headers区域添加一条请求头:
    • 键:Accept
    • 值:application/json
  3. 修改「send_message」组件的消息内容为:
    {{ widget.http_request.body.Transcriptions.Transcription.TranscriptionText }}
    
    这样就能直接提取转写文本,无需处理XML。

方法二:用Liquid解析XML(适配现有XML响应)

如果必须保留XML响应格式,可以使用Twilio支持的Liquid xml过滤器解析XML字符串,然后逐层访问目标节点:
在「send_message」组件的消息框中替换为以下Liquid代码:

{{ widget.http_request.body | xml | at: "TwilioResponse" | at: "Transcriptions" | at: "Transcription" | at: "TranscriptionText" }}

如果返回的Transcription是数组形式(比如存在多个转写记录),可添加first方法取第一条:

{{ widget.http_request.body | xml | at: "TwilioResponse" | at: "Transcriptions" | at: "Transcription" | first | at: "TranscriptionText" }}

说明:

  • xml过滤器:将XML字符串转换为Liquid可遍历的对象
  • at方法:按节点名称逐层访问XML结构中的内容
  • 对应你的XML层级:TwilioResponse → Transcriptions → Transcription → TranscriptionText

内容的提问来源于stack exchange,提问作者koolaid-kid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 00:45:36