/** * Creates a subscription, which generates notification messages from * AT&T to the configured endpoint. * * @method createSubscription * * @param {array} events array containing "TEXT", "MMS", or both. * @param {string} callbackData to be returned with any requested notifications. * @param {number} expiresIn seconds until the subscription expires. * * @return {string} JSON description of created subscription. * @throws ServiceException if API request was not successful. */ public function createSubscription($events, $callbackData, $expiresIn) { $token = $this->getSessionConsentToken('MIM'); $webhooksSrvc = new WebhooksService($this->base_url, $token); $channelId = $this->getChannelId(); $createArgs = new CreateSubscriptionArgs($channelId, $events, $callbackData, $expiresIn); return $webhooksSrvc->createNotificationSubscription($createArgs); }
if (isset($_SESSION['subscriptionId'])) { throw new Exception('You must first delete your existing subscription.'); } $events = array(); if (isset($_REQUEST['subscriptionText'])) { $events[] = 'TEXT'; } if (isset($_REQUEST['subscriptionMms'])) { $events[] = 'MMS'; } if (count($events) == 0) { throw new Exception("You must select at least one of Text or MMS"); } envinit(); $webhooksSrvc = new WebhooksService(getFqdn(), getSessionToken()); $callbackData = $_REQUEST['callbackData']; if ($callbackData == '') { $callbackData = null; } $args = new CreateSubscriptionArgs(CHANNEL_ID, $events, $callbackData, EXPIRES_IN); $response = $webhooksSrvc->createNotificationSubscription($args); $subscription = $response->getSubscription(); $subscriptionId = $subscription->getSubscriptionId(); $_SESSION['subscriptionId'] = $subscriptionId; $_SESSION['subscriptionExpiry'] = EXPIRES_IN + time(); $arr = array('success' => true, 'text' => 'Subscription created.'); } catch (Exception $e) { $arr = array('success' => false, 'text' => $e->getMessage()); } echo json_encode($arr); /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */