/** * {@inheritDoc} * @see \DMA\Friends\Classes\Notifications\Channels\Listenable::read() */ public function read() { $message = new IncomingMessage($this->getKey()); $message->from('Julio'); $message->setContent(' DMA 345345.34543 '); return [$message]; }
/** * {@inheritDoc} * @see \DMA\Friends\Classes\Notifications\Channels\Webhook::webhook() */ public function webhook(array $request) { $httpCode = 200; try { $msg = new IncomingMessage($this->getKey()); $msg->from($request['From']); $msg->setContent($request['Body']); // TODO : this should be reusable for other channels $key = $this->getKey(); $event = strtolower("dma.channel.{$key}.incoming.data"); Event::fire($event, [[$msg]]); Log::debug('Processed Twilio incoming SMS', $msg->getData()); } catch (\Exception $e) { Log::error('Processing Twilio webhook request', $request); Log::error(sprintf('Processing Twilio webhook: %s', $e)); $httpCode = 500; } // Response message was read ok return \Response::make('<Response></Response>', $httpCode); }
/** * {@inheritDoc} * @see \DMA\Friends\Classes\Notifications\Channels\Listenable::readChannel() */ public function read() { //https://api.twitter.com/1.1/search/tweets.json $url = 'https://api.twitter.com/1.1/search/tweets.json'; $requestMethod = 'GET'; $getfield = '?q=' . Settings::get('twitter_search_hashtag'); $maxId = Null; if ($sinceId = Settings::set('twitter_since_id') && ($maxId = Settings::get('twitter_max_id'))) { $getfield = $getfield . '&since_id=' . $sinceId; $getfield = $getfield . '&max_id=' . $maxId; } $client = $this->getClient(); $response = $client->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(); // Convert results to php objects $result = json_decode($response); // Convert tweets into messages $tweetIds = []; $messages = []; foreach ($result->statuses as $tweet) { $tweetId = $tweet->id; // Because max_id is also includes the tweet that we have already // processed if max_id is present we remove this tweet from the messages. if ($tweetId != $maxId) { $tweetIds[] = $tweet->id; $msg = new IncomingMessage($this->getKey()); $msg->from($tweet->user->id, $tweet->user->name); $msg->setContent($tweet->text); $messages[] = $msg; } } // Get max_id and since_id // Further information on this Twitter parameters go to // https://dev.twitter.com/rest/public/timelines Settings::set('twitter_max_id', min($tweetIds)); Settings::set('twitter_since_id', max($tweetIds)); return $messages; }