Skip to content

Instantly share code, notes, and snippets.

@JRyven
Last active October 26, 2021 08:42
Show Gist options
  • Save JRyven/e5d79eb83e0d144c3b66d32dfed5f250 to your computer and use it in GitHub Desktop.
Save JRyven/e5d79eb83e0d144c3b66d32dfed5f250 to your computer and use it in GitHub Desktop.
Trigger Twilio MMS when MMS is Received
<?php
/**
* Send Information to Twilio, Require SKD https://www.twilio.com/docs/libraries/php
*
*
*/
require __DIR__ . '/twilio/Twilio/autoload.php';
use Twilio\Rest\Client;
/**
* FORWARD MMS
*
* Under Active Phone Numbers in Twilio, you must configure a webhook to point to your
* website. Ensure that the following code is able to fire when Twilio sends a $_POST
* to your webhook URL.
*/
function twilio__text___functions___forward_MMS(){
if ($_POST){
// Your Account SID and Auth Token from twilio.com/console
$sid = '############################';
$token = '############################';
$client = new Client($sid, $token);
$from='';
if($_POST['From']):
$from = $_POST['From'];
endif;
$mediaCount = '';
$images = array();
if ($_POST['NumMedia'] > 0):
$mediaCount = $_POST['NumMedia'];
$images = array();
for($i = 0; $i < $mediaCount ; $i++) {
$images['mediaUrl'.$i] = $_POST['MediaUrl'.$i];
}
endif;
// Send the a text message to the company owner
$client->messages->create(
// form submitter is recipient for this message
'+12223334444',
array(
'from' => '+13333334444', // A Twilio phone number you purchased at twilio.com/console
'body' => 'Someone replied to your Twilio number. Their number is: '.$from,
'mediaUrl' => $images,
)
);
}
}
add_action( 'init', 'twilio__text___functions___forward_MMS');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment