Twilio:接收短信并使用正文内容做点什么

tve*_*his 4 ruby ruby-on-rails twilio

我很难理解Twilio.我已经阅读了文档,并计划再次阅读它们,但我希望得到一些指示.我在我的应用程序中使用Ruby on Rails.

我想要做的是能够从用户接收带有正文的文本消息.然后,我希望能够在模型中保存那些文本.我该怎么做呢?

谢谢!

pdo*_*obb 5

Twilio号码可以与回调URL相关联,它将在收到SMS时发送POST请求.应该自定义此回调URL以指向您将用于处理SMS的应用程序中的控制器.从那里,您可以阅读params哈希,了解收到的SMS消息的详细信息.值得注意的:params['From']params['Body'].将这些参数中的文本存储到您喜欢的任何模型中!

Twilio回调网址

http<s>://<your domain.com>/sms
Run Code Online (Sandbox Code Playgroud)

路线

resource :sms, only: :create
Run Code Online (Sandbox Code Playgroud)

调节器

class SmsController < ApplicationController
  skip_before_filter :force_ssl # You may need this if your app uses https normally

  def create
    # Do something with params['From'] -- contains the phone number the SMS came from
    # Do something with params['Body'] -- contains the text sent in the SMS

    # <Reponse/> is the minimum to indicate a "no response" from Twilio
    render xml: "<Response/>"
  end
end
Run Code Online (Sandbox Code Playgroud)