拨打号码Twilio号码以触发TWILM Bin

时间:2017-01-24 18:48:50

标签: twilio twilio-php

我们正在尝试创建一个工作流程,最终将联系表单中的潜在客户与业务所有者联系起来。

工作流程如下: 1)铅填写联系表格 2)使用Stamplay与Unbounce集成,主管收到一个文本,询问他们是否想要联系“Now”或“Later”。

让我们一起去看看“现在”

3)Lead说“现在”,它将访问webhook URL以决定下一步该做什么。

在这种特殊情况下,说“现在”,将触发TWIML bin来拨打业主。如果业主没有接听/忙碌,那么我们会向主管发送文字,要求他们发送带有“姓名”和“日期/时间”的后续文字。

4)主管回复了包含此信息的文本,然后业主和主管都收到有关约会的单独通知。

当用户直接拨打Twilio号码时,我已经能够成功完成整个工作流程(不是以编码方式使用关键字,这是我需要帮助的地方)。

来电时 - > TWIML bin

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Pause length="4"/>
  <Say>Please hold, while I connect your call.</Say>
  <Pause length="4"/>
  <Dial timeout="10"> business owner number </Dial>
  <Pause length="4"/>
  <Sms>I am currently unavailable. If you'd like me to get in touch, pls reply back with your name, and a time that would work best for you. Thanks, Adam</Sms>
</Response>

收到短信时 - &gt; webhook网址

<?php
// Require the bundled autoload file - the path may need to change
// based on where you downloaded and unzipped the SDK
require __DIR__ . '/twilio-php-master/Twilio/autoload.php';

// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;

// Your Account SID and Auth Token from twilio.com/console
$sid = 'xyz';
$token = 'xyz';
$client = new Client($sid, $token);

$number = $_POST['From'];
$body = $_POST['Body'];

//Sends a message to the owner
$sms = $client->account->messages->create(
    // Cell of owner
    '12345',
    array(
        // A Twilio phone number you purchased at twilio.com/console
        'from' => "78900",
        // Lead's reply sent to owner asNotification
        'body' => "Hi <name>. You have a new lead. The information for this lead is: $body. You can contact them at $number"
    )
);

//Sends a message to the lead
$sms = $client->account->messages->create(
    // Cell of Lead
    $number,
    array(
        // A Twilio phone number you purchased at twilio.com/console
        'from' => "78900",
        // Notification Message sent to Lead
        'body' => "This is a confirmation that I have received your information, and will be in contact with you soon. Thanks, <name>."
    )
);

我遇到问题的主要原因是“现在”,以触发业主和潜在客户之间的电话。

这是我一直试图使用的代码,除了我一直在接收 11200 HTTP检索失败不停。我还试图使用$ client-&gt; account-&gt; calls-&gt; create,因为这是我用来成功发送消息的内容。

// Read TwiML at this URL when a call connects (attempt to connect to owner)
$call = $client->calls->create(
  'lead-number', // Call this number
  '78900', // From a valid Twilio number
  array(
      'url' => TWIML Bin of Interest
  )
);

任何人都知道我能做什么?

1 个答案:

答案 0 :(得分:0)

查看creating a dynamic response的示例:

<?php
// Get the PHP helper library from twilio.com/docs/php/install

require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Twiml;

$response = new Twiml;
$body = $_REQUEST['Body'];

if( $body == 'hello' ){
    $response->message('Hi!');
}else if( $body == 'bye' ){
    $response->message('Goodbye');
}
print $response;

在您的情况下,您将修改if&#34; now&#34;在$body中,您可以创建代码看起来很适合的调用。

$call = $client->calls->create(
    "+1415XXXXXXX", "+1415XXXXXXX",
    array("url" => "link_to_twiml_bin")
);

关于11200 HTTP检索错误,请查看possible solutions here特别是:

  

确保您的Web服务器允许HTTP POST请求为静态   资源(如果URL引用.xml或.html文件)