我正在尝试将Twilio SMS与我的Rails应用程序集成,但我可以使用某个方向。 看一些其他人如何完成这个的代码示例会很棒。您可以推荐的任何内容都很棒。谢谢!
答案 0 :(得分:1)
twilio-ruby宝石对我们来说非常有用。有关如何执行此操作的详细信息取决于您的要求,但作为在创建新博客帖子后发送文本通知的快速而肮脏的示例:
在Gemfile中
gem 'twilio-ruby', require: 'twilio-ruby'
在app / models / post.rb
中class Post
ADMIN_NUMBER = '555-1212'
TWILIO_PHONE = '555-2121'
belongs_to :user
after_create :send_notification!
def send_notification!
# ideally tokens should not be in version control, stored on an external file and pulled in here
account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
# set up a client to talk to the Twilio REST API
@client = Twilio::REST::Client.new account_sid, auth_token
@client.account.messages.create(
:from => TWILIO_PHONE,
:to => ADMIN_NUMBER,
:body => "Post created by #{user.email}"
)
end
end
答案 1 :(得分:0)
你试过这个tutorial吗?它的源代码为here on github。
你也可以在github上使用这个search。