Exemplo n.º 1
0
 /**
  * Response for intended actions
  *
  * @return bool
  */
 private function responseIntendedAction()
 {
     $waiting = $this->storage->get($this->getLeadId(), '_wait');
     // We set previous_waiting to back to support $bot->keep() method
     $this->conversation->set('previous_intended_action', $waiting);
     if (!empty($waiting)) {
         $this->storage->set($this->getLeadId(), '_wait', false);
         // Get Nodes for intended actions.
         if (is_numeric($waiting)) {
             $nodes = Node::find($waiting);
             if (!empty($nodes)) {
                 $nodes = [$nodes];
             }
         } else {
             $nodes = Node::findByTypeAndPattern('intended', $waiting);
         }
         $this->response($nodes);
         return true;
     }
     return false;
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 /**
  * Add answer to node
  *
  * @param Mixed $answers Message
  * @param String $node_type Node Type
  * @param null $asks Question
  *
  * @return Node
  */
 public function addNode(array $answers, $node_type, $asks = null)
 {
     foreach ($answers as $index => $answer) {
         if (isset($answer['type']) && isset($answer['content']) && is_callable($answer['content'])) {
             $answer['content'] = $this->serializer->serialize($answer['content']);
         }
         $answers[$index] = $answer;
     }
     $this->current_node = Storage::addNode($answers, $node_type, $asks);
     return $this->current_node;
 }