如何使用 Twilio 接收来自用户的文本消息并使用消息回复该文本? [英] How do I use Twilio to receive text messages from users and reply to that text with a message?

查看:47
本文介绍了如何使用 Twilio 接收来自用户的文本消息并使用消息回复该文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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:

  1. 获取 twilio-ruby 辅助库.
  2. 将您的 SMS Url 指向您要调用的 Rails 控制器/操作
  3. 处理传入请求 &执行您的业务逻辑
  4. 不是返回 HTML,而是返回 TwiML
  1. Grab the twilio-ruby helper library.
  2. Point your SMS Url to the Rails controller/action you'd like to invoke
  3. Process the incoming request & execute your business logic
  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆