问题描述
仅使用一个 TwiML bin,是否可以混合使用语音和 SMS 动词?我尝试时出错.
Using only a single TwiML bin, is it possible to mix voice and SMS verbs? I get errors when I try.
例如,一个电话打到 Twilio 号码上,TwiML 会首先发送一个 SMS .另一个例子:当拨号未连接时,使用混合语音/短信发送短信进行处理.
For example, a call comes into a Twilio number, TwiML would first send an SMS <Message to="+18005551212"> {{From}}: <Body>Hello World!</Body> </Message>
then forward the call <Dial>+18005551212</Dial>
. Another example: use mixed Voice/SMS to send an SMS for handling when Dial doesn't connect.
如果目前无法实现,TwiML voice & 是否存在技术原因?TwiML SMS 无法进一步开发以实现互操作?
If it's not possible currently, is there a technical reason why TwiML voice & TwiML SMS couldn't be further developed to be interoperable?
推荐答案
Twilio 开发人员布道者在这里.
Twilio developer evangelist here.
想在这里跟进其他评论.如果您只是使用 TwiML Bin 来响应来电并且想要发送 SMS 消息,那么 动词就是你想要的.
Wanted to follow up with the other comments here. If you are just using a TwiML Bin to respond to an incoming call and you want to send SMS messages then the <Sms>
verb is what you want.
但是,它已被弃用. 也不像消息 TwiML 中的
动词那样最新.它不能发送超过 160 个字符的消息或媒体消息或使用消息服务.
However, it is deprecated. <Sms>
is also not as up to date as the <Message>
verb in messaging TwiML. It can't send messages over 160 characters or media messages or use messaging services.
建议从 TwiML Bin 继续使用 REST API 发送消息,同时返回 TwiML 以控制调用.您可以使用 Twilio Function 来完成此操作,因此您仍然不需要托管任何内容.这是一个简单的例子:
The recommendation is to move on from a TwiML Bin and send the message using the REST API while returning TwiML to control the call. You could do this with a Twilio Function so you still wouldn't need to host anything. Here's a quick example:
exports.handler = function(context, event, callback) {
const twilioClient = context.getTwilioClient();
twilioClient.messages.create({
to: TO_NUMBER,
from: FROM_NUMBER
body: "Hello world"
}).then(function() {
const twiml = new Twilio.twiml.VoiceResponse();
twiml.dial(TO_NUMBER);
callback(null, twiml);
});
}
让我知道这是否有帮助.
Let me know if that helps at all.
这篇关于TwiML bin 是否可以同时使用 Voice &短信功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!