Rubenwouters\CrmLauncher\ApiCalls\FetchFacebookContent::fetchPrivateConversations PHP Method

fetchPrivateConversations() public method

Fetches all private conversations from Facebook
public fetchPrivateConversations ( ) : array | Illuminate\View\View
return array | Illuminate\View\View
    public function fetchPrivateConversations()
    {
        $fb = initFb();
        $token = $this->config->FbAccessToken();
        try {
            $posts = $fb->get('/' . config('crm-launcher.facebook_credentials.facebook_page_id') . '/conversations?fields=id,updated_time', $token);
            return json_decode($posts->getBody());
        } catch (Exception $e) {
            getErrorMessage($e->getCode());
            return back();
        }
    }

Usage Example

 /**
  * Handles all private conversations from Facebook
  * @return void
  */
 public function collectPrivateConversations()
 {
     $newest = $this->message->getNewestMessageDate();
     $conversations = $this->facebookContent->fetchPrivateConversations();
     foreach ($conversations->data as $key => $conversation) {
         if (changeFbDateFormat($conversation->updated_time) > $newest) {
             $this->collectPrivateMessages($conversation, $newest);
         }
     }
 }