original_string: public static function send_messages_to_conversation(int $conversationid, array $messages = []) {
          global $CFG, $USER;
  
          // Check if messaging is enabled.
          if (empty($CFG->messaging)) {
              throw new moodle_exception('disabled', 'message');
          }
  
          // Ensure the current user is allowed to run this function.
          $context = context_system::instance();
          self::validate_context($context);
  
          $params = self::validate_parameters(self::send_messages_to_conversation_parameters(), [
              'conversationid' => $conversationid,
              'messages' => $messages
          ]);
  
          $messages = [];
          foreach ($params['messages'] as $message) {
              $createdmessage = \core_message\api::send_message_to_conversation($USER->id, $params['conversationid'], $message['text'],
                  $message['textformat']);
              $createdmessage->text = message_format_message_text((object) [
                  'smallmessage' => $createdmessage->text,
                  'fullmessageformat' => external_validate_format($message['textformat']),
                  'fullmessagetrust' => $createdmessage->fullmessagetrust
              ]);
              $messages[] = $createdmessage;
          }
  
          return $messages;
      }
code: public static function send_messages_to_conversation(int $conversationid, array $messages = []) {
          global $CFG, $USER;
  
          // Check if messaging is enabled.
          if (empty($CFG->messaging)) {
              throw new moodle_exception('disabled', 'message');
          }
  
          // Ensure the current user is allowed to run this function.
          $context = context_system::instance();
          self::validate_context($context);
  
          $params = self::validate_parameters(self::send_messages_to_conversation_parameters(), [
              'conversationid' => $conversationid,
              'messages' => $messages
          ]);
  
          $messages = [];
          foreach ($params['messages'] as $message) {
              $createdmessage = \core_message\api::send_message_to_conversation($USER->id, $params['conversationid'], $message['text'],
                  $message['textformat']);
              $createdmessage->text = message_format_message_text((object) [
                  'smallmessage' => $createdmessage->text,
                  'fullmessageformat' => external_validate_format($message['textformat']),
                  'fullmessagetrust' => $createdmessage->fullmessagetrust
              ]);
              $messages[] = $createdmessage;
          }
  
          return $messages;
      }
code_tokens: public static function send_messages_to_conversation ( int $ conversationid , array $ messages = [ ] ) { global $ CFG , $ USER ; // Check if messaging is enabled. if ( empty ( $ CFG -> messaging ) ) { throw new moodle_exception ( 'disabled' , 'message' ) ; } // Ensure the current user is allowed to run this function. $ context = context_system :: instance ( ) ; self :: validate_context ( $ context ) ; $ params = self :: validate_parameters ( self :: send_messages_to_conversation_parameters ( ) , [ 'conversationid' => $ conversationid , 'messages' => $ messages ] ) ; $ messages = [ ] ; foreach ( $ params [ 'messages' ] as $ message ) { $ createdmessage = \ core_message \ api :: send_message_to_conversation ( $ USER -> id , $ params [ 'conversationid' ] , $ message [ 'text' ] , $ message [ 'textformat' ] ) ; $ createdmessage -> text = message_format_message_text ( ( object ) [ 'smallmessage' => $ createdmessage -> text , 'fullmessageformat' => external_validate_format ( $ message [ 'textformat' ] ) , 'fullmessagetrust' => $ createdmessage -> fullmessagetrust ] ) ; $ messages [ ] = $ createdmessage ; } return $ messages ; }
docstring: Send messages from the current USER to a conversation.
  
  This conversation may be any type of conversation, individual or group.
  
  @param int $conversationid the id of the conversation to which the messages will be sent.
  @param array $messages An array of message to send.
  @return array the array of messages which were sent (created).
  @since Moodle 3.6
docstring_tokens: Send messages from the current USER to a conversation .