/**
  * Sends an IMMN to a recipient,
  *
  * @method sendImmnMessage
  * 
  * @param string      $address   addresses to which the specified messages will be sent. 
  * @param string|null $text      text body of message or null if none
  * @param string|null $subject   subject of message or null if none
  * @param array|null  $fnames    file names of attachments or null if none 
  * @param bool|null   $isGroup   whether to send as broadcast or null to use default
  *
  * @return {Response} Returns Response object
  * @throws ServiceException if API request was not successful.
  */
 public function sendImmnMessage($address, $text, $subject, $fnames = null, $isGroup = false)
 {
     // Parse address(es)
     $address_array = array();
     if (strstr($address, ",")) {
         // If it's csv, split and iterate over each value prepending each value with "tel:"
         $address = explode(",", $address);
         foreach ($address as $key => $value) {
             // Determine if string is tel, short or email
             array_push($address_array, $this->parseAddress($value));
         }
     } else {
         array_push($address_array, $this->parseAddress($address));
     }
     $token = $this->getSessionConsentToken('IMMN');
     $immnSrvc = new IMMNService($this->base_url, $token);
     return $immnSrvc->sendMessage($address_array, $text, $subject, $fnames, $isGroup, true);
 }
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/IMMN/IMMNService.php';
require_once __DIR__ . '/../lib/Util/Util.php';
use Att\Api\IMMN\IMMNService;
use Att\Api\Util\Util;
$arr = null;
try {
    envinit();
    $immnSrvc = new IMMNService(getFqdn(), getSessionToken());
    $addrs = Util::convertAddresses($_POST['address']);
    $msg = $_POST['sendMsgInput'];
    $subject = $_POST['sendSubjectInput'];
    $group = isset($_POST['groupCheckbox']);
    $id = $immnSrvc->sendMessage($addrs, $msg, $subject, null, $group);
    $arr = array('success' => true, 'text' => 'id: ' . $id);
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 public function handleSendMessage()
 {
     $vnames = array('sendMessage', 'address', 'message', 'subject', 'attachment', 'groupCheckBox');
     $this->copyToSession($vnames);
     if (!isset($_SESSION['sendMessage'])) {
         return;
     }
     try {
         if (!isset($_REQUEST['groupCheckBox'])) {
             unset($_SESSION['groupCheckBox']);
         }
         $addr = $this->convertAddresses($_SESSION['address']);
         $msg = $_SESSION['message'];
         $subject = $_SESSION['subject'];
         $attachment = $_SESSION['attachment'];
         if (strcmp($attachment, 'None') == 0) {
             $attachment = null;
         } else {
             $attachment = array($this->_attachmentsFolder . '/' . $attachment);
         }
         $checkbox = isset($_REQUEST['groupCheckBox']);
         $_SESSION['checkbox'] = $checkbox;
         $immnSrvc = new IMMNService($this->apiFQDN, $this->getSessionToken());
         $this->clearSession(array('sendMessage'));
         $id = $immnSrvc->sendMessage($addr, $msg, $subject, $attachment);
         $this->results[C_SEND_MSG] = $id;
     } catch (Exception $e) {
         $this->errors[C_SEND_MSG] = $e->getMessage();
         $this->clearSession(array('sendMessage'));
     }
 }
Example #4
0
$oauthCode = "ENTER VALUE!";
// Create the service for requesting an OAuth access token
$osrvc = new OAuthTokenService('https://api.att.com', $clientId, $clientSecret);
// Get the OAuth token using the OAuth code.
$token = $osrvc->getTokenUsingCode(new OAuthCode($oauthCode));
// Create the service for interacting with the In-App Messaging API.
$immnSrvc = new IMMNService('https://api.att.com', $token);
// The following lines of code can be used to test the method calls for
// the IMMNService class. To test a specific method, comment out
// the other method.
/* This try/catch block tests the sendMessage method. */
try {
    // Specify the address to where the message is sent.
    $addr = array('ENTER VALUE!');
    // Send a test message.
    $response = $immnSrvc->sendMessage($addr, 'Text', 'Subject');
    echo "msgId: " . $response . "\n";
} catch (ServiceException $se) {
    echo $se->getErrorResponse();
}
/* This try/catch block tests the getMessageList method.*/
try {
    // Enter the number of messages to include in the list.
    $limit = 'ENTER VALUE!';
    // Enter the offset to the first message.
    $offset = 'ENTER VALUE!';
    // Send the request to get the message list.
    $msgList = $immnSrvc->getMessageList($limit, $offset);
    echo "total: " . $msgList->getTotal() . "\n";
} catch (ServiceException $se) {
    echo $se->getErrorResponse();