不允许回复使用moodle api发送的消息

我试图制作一个 PHP 脚本来向 Moodle 中的其他人发送一条消息。


我看过消息 api,我做了这个


 $message = new \core\message\message();

$message->component = 'moodle';

$message->name = 'instantmessage';

$message->userfrom = 318;

$message->userto = 323;

$message->subject = 'message subject 1';

$message->fullmessage = 'message body';

$message->fullmessageformat = FORMAT_MARKDOWN;

$message->fullmessagehtml = '<p>message body</p>';

$message->smallmessage = 'small message';

$message->notification = '0';

$message->contexturl = 'http://GalaxyFarFarAway.com';

$message->contexturlname = 'Context name';

$message->replyto = "random@example.com";

$content = array('*' => array('header' => ' test ', 'footer' => ' test ')); // Extra content for specific processor

$message->set_additional_content('email', $content);

$message->courseid = 107; // This is required in recent versions, use it from 3.2 on https://tracker.moodle.org/browse/MDL-47162


$messageid = message_send($message)

问题是,当用户 323 在 Moodle 内部消息中创建的聊天中发送回复消息时,会发生错误(消息被红色包围)并且永远不会到达。


我真的希望它能够像正常对话一样做出回应。


我不知道我是否走错了。


慕雪6442864
浏览 125回答 2
2回答

幕布斯7119047

我终于找到了!!!问题是首先您必须在用户之间创建对话,然后发送消息if(!\core_message\api::get_conversation_between_users([$userfrom, $userto ])){&nbsp; &nbsp; $conversation = \core_message\api::create_conversation(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $userfrom,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $userto&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );}$message = new \core\message\message();$message->component = 'moodle';&nbsp; &nbsp; $message->name = 'instantmessage';&nbsp; &nbsp; $message->userfrom = $userfrom ;&nbsp; &nbsp; $message->userto = $userto;&nbsp; &nbsp; $message->subject = 'Nuevo mensaje';&nbsp; &nbsp; $message->fullmessage = $msg;&nbsp; &nbsp; $message->fullmessageformat = FORMAT_MARKDOWN;&nbsp; &nbsp; $message->fullmessagehtml = $msg;&nbsp; &nbsp; $message->smallmessage = $msg;&nbsp; &nbsp; $message->notification = '0';&nbsp; &nbsp; $message->contexturl = '';&nbsp; &nbsp; $message->contexturlname = 'Context name';&nbsp; &nbsp; $message->replyto = "###@######.###";&nbsp; &nbsp; $content = array('*' => array('header' => '', 'footer' => ''));&nbsp;&nbsp; &nbsp; $message->set_additional_content('email', $content);&nbsp; &nbsp; $message->courseid = 107;&nbsp;&nbsp; &nbsp; message_send($message);

一只萌萌小番薯

这可能是因为 userto 和 userfrom 需要是对象,例如:$userto = $DB->get_record('user', array('id' => 323));$message->userfrom = $USER; // Current user.$message->userto = $userto;
打开App,查看更多内容
随时随地看视频慕课网APP