Laravel/Twilio接收短信 [英] Laravel/Twilio Receiving SMS

查看:64
本文介绍了Laravel/Twilio接收短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Laravel和 https://github.com/aloha/laravel-twilio 这使我能够非常轻松地发送短信.问题来了,我希望用户能够偶尔回复,并且我不确定如何设置网络挂钩等.我已经阅读了Twilio文档,但并没有太大帮助,似乎也没有解决该问题的"Laravel"方法.

I use Laravel with https://github.com/aloha/laravel-twilio which allows me to send SMS really easily. The issue comes in that I'd like users to be able to respond back occasionally and I'm unsure of how to setup the webhooks and such. I've read through the Twilio documentation but it hasn't helped a lot, nor does there seem to be a "Laravel" method to solve this.

是否有用于通过Laravel接收文本的库或说明?我尝试研究一下,得到的只是Twilio PHP文档或上面的链接GitHub.我只是不确定如何设置它,我不具备将Laravel的结构与PHP webhooks链接的适用知识.

Are there any libraries or instructions for receiving texts through Laravel? I've tried to look into it and all I get is the Twilio PHP docs or the linked GitHub above. I'm just unsure of how to set it up, I don't have the applicable knowledge of Laravel's structure to link it with the PHP webhooks.

在我问的同时,是否仍要在Twilio消息中添加退货?

Also, while I'm asking, is there anyway to add a return in a Twilio message?

推荐答案

此处是Twilio开发人员的福音.

Twilio developer evangelist here.

当有人向您的Twilio号码发送消息并且您已经为应用程序设置了网络挂钩时,​​会发生这种情况.

When someone sends a message to your Twilio number and you have setup a webhook to your application here's what happens.

Twilio将向您的应用程序的HTTP POST请求webhook网址.该请求将包含有关正文中消息的所有信息.该请求的格式为 application/x-www-form-urlencoded .对于您的Laravel应用程序,这与在网页上提交常规表单的用户相同.这意味着您可以像在常规POST请求中一样访问数据.这样的事情可能会让您入门:

Twilio will make an HTTP POST request to your application's webhook URL. That request will contain everything about the message in the body. The request is made in the format application/x-www-form-urlencoded. To your Laravel application, this is the same as a user submitting a regular form on a web page. This means you can access the data the same way you would in a regular POST request. Something like this might get you started:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TwilioController extends Controller
{
    /**
     * receive an incoming SMS message
     *
     * @param  Request  $request
     * @return Response
     */
    public function receiveSMS(Request $request)
    {
        $messageBody = $request->input('Body');
        $phoneNumber = $request->input('From');

        // do something with the message
    }
}

您可以使用 TwiML 来响应Webhook,这只是一组XMLTWilio可以理解的标签.或者,如果您仅返回200 OK响应,则可以将现有的Twilio集成与Laravel软件包一起使用来发送答复.

You can respond to the webhook with TwiML, which is just a set of XML tags that TWilio understands. Or, if you just return a 200 OK response, you can use your existing Twilio integration with the Laravel package to send replies too.

让我知道这是否有帮助.

Let me know if that helps at all.

这篇关于Laravel/Twilio接收短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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