【问题标题】:How to get content of message from users in my site using twilio如何使用 twilio 从我的站点中的用户获取消息内容
【发布时间】:2022-09-23 13:31:35
【问题描述】:

大家好吗? 我的网站是基于 PHP 的。 我是 twilio 的新手,并以此构建简单的项目。 所以我应该实现的是使用 twilio 向用户发送消息,然后在我的站点中再次接收来自用户的消息。

<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once \'./vendor/autoload.php\';

use Twilio\\Rest\\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = \'Azzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\';
$token = \'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\';
$twilio = new Client($sid, $token);

$message = $twilio->messages
                  ->create(\"+12099216581\", // to
                           [
                               \"body\" => \"This is test\",
                               \"from\" => \"+15324394442\",
                               \"statusCallback\" => \"\"
                           ]
                  );

print($message->sid);

这是为了向我现在使用的一个用户发送消息.. 然后...

<?php
require_once \'./vendor/autoload.php\';
use Twilio\\TwiML\\MessagingResponse;

$response = new MessagingResponse();
$response->message(\'This is message 1 of 2.\');
$response->message(\'This is message 2 of 2.\');

echo $response;

我认为这段代码会用文本向用户返回文本消息...... 如果我错了,请教我...

所以我现在正在尝试这样做,但我不知道如何在我的站点中接收消息的内容。 如果你有这方面的经验,请教我。 提前致谢。

    标签: php twilio


    【解决方案1】:

    您需要为该消息响应设置 webhook

    smsUrl = 'url';
    
    $response   = $client->request("POST", "IncomingPhoneNumbers/$phone_id.json", ['auth' => [$sid, $token], 'form_params' => array("SmsUrl" => $webhook_url, "BundleSid" => $bundle_id)]);
    

    此 URL 将发布传入消息并回复消息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-01
      • 2020-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多