如何使用 Twilio 接收来自用户的文本消息并使用消息回复该文本? [英] How do I use Twilio to receive text messages from users and reply to that text with a message?
问题描述
1.) 用户向指定的 Twilio 电话号码发送短信2.) 应用程序接收此消息并将其解析为可操作的数据3.) 应用程序用一条短信回复发送者,提供所请求的信息
1.) User sends a text message to a designated Twilio phone number 2.) Application receives this message and parses it for actionable data 3.) Application replies to sender with a text message delivering the requested information
我到底是怎么用 Rails 做到这一点的?!
How the heck do I do this with rails?!
推荐答案
假设您的业务逻辑执行时间不长,那么处理文本和发送响应非常简单.以下是核心步骤:
Assuming your business logic doesn't take that long to execute, it's pretty simple to process a text and send a response. Here are the core steps:
- 获取 twilio-ruby 辅助库.
- 将您的 SMS Url 指向您要调用的 Rails 控制器/操作
- 处理传入请求 &执行您的业务逻辑
- 不是返回 HTML,而是返回 TwiML
- Grab the twilio-ruby helper library.
- Point your SMS Url to the Rails controller/action you'd like to invoke
- Process the incoming request & execute your business logic
- Instead of returning HTML, return TwiML
这是一个简单的应用程序的链接,它就是这样做的:
Here's a link to a simple app that does just this:
https://github.com/crabasa/twilio-rails-demo
更新:我写了两篇关于将 Twilio 集成到 Rails 4.x 应用程序的详细博客文章:第 1 部分 和 第 2 部分.
Update: I've written two detailed blog posts on integration Twilio into a Rails 4.x app: Part 1 and Part 2.
这篇关于如何使用 Twilio 接收来自用户的文本消息并使用消息回复该文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!