예제 #1
0
 public static function updatePersistentMenu()
 {
     $menu = Config::get('persistent_menu');
     $end_point = Request::PLATFORM_ENDPOINT . 'me/thread_settings?access_token=' . Request::$token;
     $params = ['setting_type' => 'call_to_actions', 'thread_state' => 'existing_thread'];
     if (!empty($menu)) {
         $params['call_to_actions'] = $menu;
         return Request::send($end_point, $params);
     }
     Request::send($end_point, $params, 'delete');
 }
예제 #2
0
 private function pull($lead_id)
 {
     // Todo: Check cache time and fetch new data
     if (self::has($lead_id)) {
         return;
     }
     $lead = Request::getUserProfile($lead_id);
     if (empty($lead['first_name']) || empty($lead['last_name'])) {
         return;
     }
     // Parse event to array
     $lead['user_id'] = $lead_id;
     $lead['subscribe'] = 1;
     // Then call set method
     self::set($lead);
 }
예제 #3
0
 /**
  * Response sender message
  *
  * @param $nodes
  * @param null $lead_id
  */
 public function response($nodes, $lead_id = null)
 {
     if (is_null($lead_id)) {
         $lead_id = $this->conversation->get('lead_id');
     }
     foreach ($nodes as $node) {
         /** New wait */
         if (!empty($node->wait)) {
             $this->storage->set($lead_id, '_wait', $node->wait);
         }
         // Backward compatibility
         if (array_key_exists('type', $node->answers)) {
             $node->answers = [$node->answers];
         }
         foreach ($node->answers as $answer) {
             /** Process dynamic content */
             if (isset($answer['type'])) {
                 // Backward compatibility
                 if (isset($answer['callback'])) {
                     $answer['content'] = $answer['callback'];
                 }
                 if (giga_match('%SerializableClosure%', $answer['content'])) {
                     $answer['content'] = $this->serializer->unserialize($answer['content']);
                 }
                 $return = DynamicParser::parse($answer);
                 // If the callback return, we'll send that message to user.
                 if ($return != null || !empty($return)) {
                     $answer = $this->model->parseWithoutSave($return);
                     // Answer == 0 means that answers is already parsed and it's a single message.
                     if ($answer != false) {
                         $this->request->sendMessages($answer);
                     } else {
                         $this->request->sendMessage($return);
                     }
                     continue;
                 }
             }
             $this->request->sendMessage($answer);
         }
     }
 }
예제 #4
0
 /**
  * Send a single message
  *
  * @param $message
  * @param $lead_id
  */
 private function sendMessage($message, $lead_id = null)
 {
     if (is_null($lead_id)) {
         $lead_id = Conversation::get('lead_id');
     }
     $message = Parser::parseShortcodes($message, Storage::get($lead_id));
     $message['metadata'] = 'SENT_BY_GIGA_AI';
     $body = ['recipient' => ['id' => $lead_id], 'message' => $message];
     Request::send(self::PLATFORM_ENDPOINT . "me/messages?access_token=" . self::$token, $body);
 }
예제 #5
0
 /**
  * Send Message To Leads
  *
  * @param $messages
  * @param $lead_ids
  * @return $this
  */
 private function sendMessageToLeads($messages, $lead_ids)
 {
     $lead_ids = (array) $lead_ids;
     foreach ($lead_ids as $lead_id) {
         Request::sendMessages($messages, $lead_id);
     }
 }