我可以在TwiML中插入变量吗?特别是要插入电话号码的电话号码是多少?

时间:2018-09-28 19:23:38

标签: twilio

有没有办法在TwiML中实现以下内容?目的是在Twilio上产生听起来不错的语音邮件。

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Pause length="15"/>
    <Say voice ="woman">
        You have reached the voice mail of ##The_Phone_Number_One_has_Called##.
        Please leave a message at the beep.
    </Say>
    <Record
        transcribe="true"
        />
</Response>

我有一堆Twilio号码,并希望将字符串"##The_Phone_Number_One_has_Called##"替换为呼叫者正在呼叫的号码。请咨询我是否应该为每个电话号码部署专用的TwiML。

2 个答案:

答案 0 :(得分:1)

使用带有TwiML Bin的模板和Polly声音,为Bin尝试类似的操作:


<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Pause length="15"/>
    <Say voice="Polly.Joanna">
        You have reached the voice mail of 
          <say-as interpret-as="telephone">{{To}}</say-as>.
        Please leave a message at the beep.
    </Say>
    <Record
        transcribe="true"
        />
</Response>

答案 1 :(得分:0)

您可以在服务器的代码上执行此操作。只需将“ ## The_Phone_Number_One_has_Called ##”替换为用户拨打的电话即可。

请记住,您在Twilio向服务器发送的每个请求中都获得了用户在帖子参数“ To”上拨打的号码,因此您可以从服务器返回:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Pause length="15"/>
    <Say voice ="woman">
        You have reached the voice mail of $POST["To"].
        Please leave a message at the beep.
    </Say>
    <Record
        transcribe="true"
        />
</Response>

您的服务器每次都会渲染不同的电话,而Twilio会说。请注意,$ POST [“ To”]的格式为“ + 1XXXXXXXXXX”,因此您可能要删除+1。