Start a new Conversation.
@param  \KeythKatz\TelegramBotCore\Conversation $conversation instance of a conversation.
762667
protected function startConversation(\KeythKatz\TelegramBotCore\Conversation $conversation): void
	{
		$conversation->setBot($this->bot);
		$conversation->setMessage($this->message);
		$conversation->start();
	}
139785
protected function newConversation($receiverId)
    {
        $conversationId = $this->isConversationExists($receiverId);
        $user = $this->getSerializeUser($this->authUserId, $receiverId);

        if ($conversationId === false) {
            $conversation = $this->conversation->create([
                'user_one' => $user['one'],
                'user_two' => $user['two'],
                'status' => 1,
            ]);

            if ($conversation) {
                return $conversation->id;
            }
        }

        return $conversationId;
    }
1344078
public function getConversationMessageById($conversationId)
    {
        if ($this->conversation->checkUserExist($this->userId, $conversationId)) {
            $channel = $this->getChannelName($conversationId, 'chat_room');

            return $this->conversation->getConversationMessageById($conversationId, $this->userId, $channel);
        }

        abort(404);
    }
1212484
protected final void startConversation(Event event, String methodName) {
        startConversation(event.getSender().getId(), methodName);
    }
890027
public function start($args)
    {
        $this->_header = false;
        parent::start($args);
        $this->write("\n1..{$args['total']}\n");
    }
371097
public function begin() {
        if($this->isInTransaction()) {
            throw new \Exception('You cannot start a new transaction once you are already in one (Originally started at: ' . self::$stackTrace . ')');
        } else {
            $e = new \Exception();
            self::$stackTrace = $e->getTraceAsString();
        }
        $transactionManager = new TransactionManager();
        $transactionManager->setDbService($this->getDbService());
        $this->setTransaction($transactionManager->get());
    }
636330
public Task startTask(String taskId, boolean beginConversation) {
    if(beginConversation) {
      Conversation conversation = conversationInstance.get();
      if(conversation.isTransient()) {
       conversation.begin();
      }
    }
    return startTask(taskId);
  }
1139286
public function start($message, $maxSteps)
    {
        $this->info($message);

        if ($this->progressBar instanceof ProgressBar) {
            $this->progressBar->setMessage($message);
            $this->progressBar->start($maxSteps);
        }
    }
330536
public static function mark_all_conversation_messages_as_read(int $userid, int $conversationid) {
        global $CFG;

        // Check if messaging is enabled.
        if (empty($CFG->messaging)) {
            throw new moodle_exception('disabled', 'message');
        }

        $params = array(
            'userid' => $userid,
            'conversationid' => $conversationid,
        );
        $params = self::validate_parameters(self::mark_all_conversation_messages_as_read_parameters(), $params);

        $context = context_system::instance();
        self::validate_context($context);

        $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
        core_user::require_active_user($user);

        if (\core_message\api::can_mark_all_messages_as_read($params['userid'], $params['conversationid'])) {
            \core_message\api::mark_all_messages_as_read($params['userid'], $params['conversationid']);
        } else {
            throw new moodle_exception('accessdenied', 'admin');
        }
    }
1358494
public function start($participants, $data = [])
    {
        $conversation = $this->create(['data' => $data]);

        if ($participants) {
            $conversation->addParticipants($participants);
        }

        return $conversation;
    }
1241547
public function dialog()
    {
        //if session has not started
        if (!session_id()) {
            //start session
            session_start();
        }
        
        //if they never tried
        if (!isset($_SESSION[self::UNAUTHORIZED])) {
            //first try
            $_SESSION[self::UNAUTHORIZED] = 1;
        } else {
            //more than one try
            $_SESSION[self::UNAUTHORIZED]++;
        }
        
        //if it's their first few tries
        if ($_SESSION[self::UNAUTHORIZED] < 3) {
            header(sprintf(self::HTTP_AUTH, $this->realm, uniqid(), md5($this->realm)));
            exit;
        }
        
        //let them try again
        unset($_SESSION[self::UNAUTHORIZED]);
        
        //you are unauthorized
        header(self::UNAUTHORIZED);
        
        //throw
        Exception::i()
            ->setMessage(self::UNAUTHORIZED)
            ->setType(self::ERROR_TYPE)
            ->trigger();
    }
1208921
public function create(int $conversationId, Thread $thread): ?int
    {
        return $this->restClient->createResource(
            $thread,
            $thread::resourceUrl($conversationId)
        );
    }
15823
public function AddMessage($ConversationID = '') {
      $this->Form->SetModel($this->ConversationMessageModel);
      if (is_numeric($ConversationID) && $ConversationID > 0)
         $this->Form->AddHidden('ConversationID', $ConversationID);
      
      if ($this->Form->AuthenticatedPostBack()) {
         $ConversationID = $this->Form->GetFormValue('ConversationID', '');
         $Conversation = $this->ConversationModel->GetID($ConversationID, Gdn::Session()->UserID);   
         
         $this->EventArguments['Conversation'] = $Conversation;
         $this->EventArguments['ConversationID'] = $ConversationID;
         $this->FireEvent('BeforeAddMessage');
         
         $NewMessageID = $this->Form->Save();
         
         if ($NewMessageID) {
            if ($this->DeliveryType() == DELIVERY_TYPE_ALL)
               Redirect('messages/'.$ConversationID.'/#'.$NewMessageID, 302);
               
            $this->SetJson('MessageID', $NewMessageID);
            // If this was not a full-page delivery type, return the partial response
            // Load all new messages that the user hasn't seen yet (including theirs)
            $LastMessageID = $this->Form->GetFormValue('LastMessageID');
            if (!is_numeric($LastMessageID))
               $LastMessageID = $NewMessageID - 1;
            
            $Session = Gdn::Session();
            $MessageData = $this->ConversationMessageModel->GetNew($ConversationID, $LastMessageID);
            $this->Conversation = $Conversation;
            $this->MessageData = $MessageData;

            $this->View = 'messages';
         } else {
            // Handle ajax based errors...
            if ($this->DeliveryType() != DELIVERY_TYPE_ALL)
               $this->ErrorMessage($this->Form->Errors());
         }
      }
      $this->Render();      
   }
863788
public function Save($FormPostValues, $Conversation = NULL) {
      $Session = Gdn::Session();
      
      // Define the primary key in this model's table.
      $this->DefineSchema();
      
      // Add & apply any extra validation rules:      
      $this->Validation->ApplyRule('Body', 'Required');
      $this->AddInsertFields($FormPostValues);
      
      $this->EventArguments['FormPostValues'] = $FormPostValues;
      $this->FireEvent('BeforeSaveValidation');
      
      // Validate the form posted values
      $MessageID = FALSE;
      if($this->Validate($FormPostValues)) {
         $Fields = $this->Validation->SchemaValidationFields(); // All fields on the form that relate to the schema
         TouchValue('Format', $Fields, C('Garden.InputFormatter', 'Html'));
         
         $this->EventArguments['Fields'] = $Fields;
         $this->FireEvent('BeforeSave');
         
         $MessageID = $this->SQL->Insert($this->Name, $Fields);
         $this->LastMessageID = $MessageID;
         $ConversationID = ArrayValue('ConversationID', $Fields, 0);

         if (!$Conversation)
            $Conversation = $this->SQL->GetWhere('Conversation', array('ConversationID' => $ConversationID))->FirstRow(DATASET_TYPE_ARRAY);

         $Message = $this->GetID($MessageID);
         $this->EventArguments['Conversation'] = $Conversation;
         $this->EventArguments['Message'] = $Message;
         $this->FireEvent('AfterSave');
         
         // Get the new message count for the conversation.
         $SQLR = $this->SQL
            ->Select('MessageID', 'count', 'CountMessages')
            ->Select('MessageID', 'max', 'LastMessageID')
            ->From('ConversationMessage')
            ->Where('ConversationID', $ConversationID)
            ->Get()->FirstRow(DATASET_TYPE_ARRAY);
         if (sizeof($SQLR)) {
            list($CountMessages, $LastMessageID) = array_values($SQLR);
         } else { return; }
         
         // Update the conversation's DateUpdated field.
         $DateUpdated = Gdn_Format::ToDateTime();
         
         $this->SQL
            ->Update('Conversation c')
            ->Set('CountMessages', $CountMessages)
            ->Set('LastMessageID', $LastMessageID)
            ->Set('UpdateUserID', Gdn::Session()->UserID)
            ->Set('DateUpdated', $DateUpdated)
            ->Where('ConversationID', $ConversationID)
            ->Put();

         // Update the last message of the users that were previously up-to-date on their read messages.
         $this->SQL
            ->Update('UserConversation uc')
            ->Set('uc.LastMessageID', $MessageID)
            ->Set('uc.DateConversationUpdated', $DateUpdated)
            ->Where('uc.ConversationID', $ConversationID)
            ->Where('uc.Deleted', '0')
            ->Where('uc.CountReadMessages', $CountMessages - 1)
            ->Where('uc.UserID <>', $Session->UserID)
            ->Put();
         
         // Update the date updated of the users that were not up-to-date.
         $this->SQL
            ->Update('UserConversation uc')
            ->Set('uc.DateConversationUpdated', $DateUpdated)
            ->Where('uc.ConversationID', $ConversationID)
            ->Where('uc.Deleted', '0')
            ->Where('uc.CountReadMessages <>', $CountMessages - 1)
            ->Where('uc.UserID <>', $Session->UserID)
            ->Put();

         // Update the sending user.
         $this->SQL
            ->Update('UserConversation uc')
            ->Set('uc.CountReadMessages', $CountMessages)
            ->Set('Deleted', 0)
            ->Set('uc.DateConversationUpdated', $DateUpdated)
            ->Where('ConversationID', $ConversationID)
            ->Where('UserID', $Session->UserID)
            ->Put();

         // Find users involved in this conversation
         $UserData = $this->SQL
            ->Select('UserID')
            ->Select('LastMessageID')
            ->Select('Deleted')
            ->From('UserConversation')
            ->Where('ConversationID', $ConversationID)
            ->Get()->Result(DATASET_TYPE_ARRAY);
         
         $UpdateCountUserIDs = array();
         $NotifyUserIDs = array();
         
         // Collapse for call to UpdateUserCache and ActivityModel.
         $InsertUserFound = FALSE;
         foreach ($UserData as $UpdateUser) {
            $LastMessageID = GetValue('LastMessageID', $UpdateUser);
            $UserID = GetValue('UserID', $UpdateUser);
            $Deleted = GetValue('Deleted', $UpdateUser);
            
            if ($UserID == GetValue('InsertUserID', $Fields)) {
               $InsertUserFound = TRUE;
               if ($Deleted) {
                  $this->SQL->Put('UserConversation', array('Deleted' => 0, 'DateConversationUpdated' => $DateUpdated), array('ConversationID' => $ConversationID, 'UserID' => $UserID));
               }
            }
            
            // Update unread for users that were up to date
            if ($LastMessageID == $MessageID)
               $UpdateCountUserIDs[] = $UserID;
            
            // Send activities to users that have not deleted the conversation
            if (!$Deleted)
               $NotifyUserIDs[] = $UserID;
         }
         
         if (!$InsertUserFound) {
            $UserConversation = array(
               'UserID' => GetValue('InsertUserID', $Fields),
               'ConversationID' => $ConversationID,
               'LastMessageID' => $LastMessageID,
               'CountReadMessages' => $CountMessages,
               'DateConversationUpdated' => $DateUpdated);
            $this->SQL->Insert('UserConversation', $UserConversation);
         }
         
         if (sizeof($UpdateCountUserIDs)) {
            $ConversationModel = new ConversationModel();
            $ConversationModel->UpdateUserUnreadCount($UpdateCountUserIDs, TRUE);
         }
         
         $this->FireEvent('AfterAdd');

         $ActivityModel = new ActivityModel();
         foreach ($NotifyUserIDs as $NotifyUserID) {
            if ($Session->UserID == $NotifyUserID)
               continue; // don't notify self.

            // Notify the users of the new message.
            $ActivityID = $ActivityModel->Add(
               $Session->UserID,
               'ConversationMessage',
               '',
               $NotifyUserID,
               '',
               "/messages/{$ConversationID}#{$MessageID}",
               FALSE
            );
            $Story = GetValue('Body', $Fields, '');
            
            if (C('Conversations.Subjects.Visible')) {
               $Story = ConcatSep("\n\n", GetValue('Subject', $Conversation, ''), $Story);
            }
            $ActivityModel->SendNotification($ActivityID, $Story);
         }
      }
      return $MessageID;
   }
959476
public function onApplicationReady()
    {
        try {
            $this->factory->getConnection()->chatEnableManualRouting();
        } catch (\Exception $e) {
            $this->console->writeln('Error while enabling custom chat: $f00'.$e->getMessage());
            $this->logger->error("Error enabling custom chat", ['exception' => $e]);
        }
    }
849399
public function get(int $id, ConversationRequest $conversationRequest = null): Conversation
    {
        $conversationResource = $this->restClient->getResource(Conversation::class, sprintf('/v2/conversations/%d', $id));

        return $this->hydrateConversationWithSubEntities($conversationResource, $conversationRequest ?: new ConversationRequest());
    }
1341688
private function getNextStep($sessionId, $message, Context $context)
    {
        $stepData = $this->converseApi->converse($sessionId, $message, $context);

        if (null === $stepData) {
            $stepData = [];
        }

        if (isset($stepData['error'])) {
            throw new ConversationException($stepData['error'], $sessionId, $context, $stepData);
        }

        try {
            $step = StepFactory::create($stepData);
        } catch (InvalidStepException $e) {
            throw new ConversationException($e->getMessage(), $sessionId, $context, $e->getStepData());
        }

        return $step;
    }