我正在将Twilio SMS服务用于我的其中一个项目,它在Ruby中。在这种情况下,我要发送具有动态值的SMS,例如此名称属性中的Hi, {{name}}
将是动态的。我已经阅读了文档,但无法弄清楚如何实现。我正在使用ruby Twilio客户端库。但是,我可以发送普通的计划文本SMS,但不能发送具有动态内容的SMS。我当前的代码是
@connection = Twilio::REST::Client.new(@account_sid, @auth_token)
@connection.messages.create({
:from => options.fetch(:from),
:to => options.fetch(:to),
:body => options.fetch(:body)
})
def welcome_message(name)
"Hi, #{name}! welcome to our website."
end
当您传递选项时:
options = {
from: someone,
to: someone,
body: welcome_message(some_name),
}
然后分享您相同的代码段:
@connection = Twilio::REST::Client.new(@account_sid, @auth_token)
@connection.messages.create({
:from => options.fetch(:from),
:to => options.fetch(:to),
:body => options.fetch(:body)
})