Forum Replies Created
-
AuthorPosts
-
dennis
ParticipantWould it be possible to allow negative mycred charge? like to reward users for using the chat!
dennis
ParticipantHi,
See that there is already API provisioning in the source, why isn’t there documentation? Is it for internal use?
dennis
ParticipantHi,
Curious what issue you see, isnt it like oEmbed for pictures? Could you give me a hint where to implement, on my own risk ofc?dennis
Participant6.to create new threads and post messages [POST] https://<yoursite>/?rest_route=/better-messages/v1/createnewthread&JWT=JWT
// register create thread endpoint add_action('rest_api_init', function () { register_rest_route( 'better-messages/v1', '/createnewthread',array( 'methods' => 'POST', 'callback' => 'CreateNewThread', 'permission_callback' => '__return_true' )); }); function CreateNewThread($request) { $user = wp_get_current_user(); // check if user is logged in >> return error if ( $user->exists() == false) { return new WP_Error( 'User is not logged in.', 'User is not logged in.', array('status' => 404) ); } $sender_id = $user->ID; $thread_id = Better_Messages()->functions->new_message([ 'sender_id' => $sender_id, 'content' => $request['content'], 'subject' => $request['subject'], 'recipients' => $request['recipients'], 'return' => 'thread_id', 'error_type' => 'wp_error' ]); $response = new WP_REST_Response($thread_id); $response->set_status(200); return $response; }hope to save somebody else some time. don’t complain when i killed you site.
dennis
Participant5. to add messages [POST] https://<yoursite>/?rest_route=/better-messages/v1/addmessagetothread&JWT=JWT
// register add message endpoint add_action('rest_api_init', function () { register_rest_route( 'better-messages/v1', '/addmessagetothread',array( 'methods' => 'POST', 'callback' => 'AddMessageToThread', 'permission_callback' => '__return_true' )); }); // implementation function AddMessageToThread($request) { $user = wp_get_current_user(); // check if user is logged in >> return error if ( $user->exists() == false) { return new WP_Error( 'User is not logged in.', 'User is not logged in.', array('status' => 404) ); } $sender_id = $user->ID; $message_id = Better_Messages()->functions->new_message([ 'sender_id' => $sender_id, 'thread_id' => $request['thread_id'], 'content' => $request['content'], 'return' => 'message_id', ]); if ( is_wp_error( $message_id ) ) { $error = $message_id->get_error_message(); return new WP_Error( 'Unable to post message to thread.' . $error, 'Unable to post message to thread.', array('status' => 404) ); } else { $response = new WP_REST_Response($message_id); $response->set_status(200); return $response; } }dennis
Participantok, hacked-up some wordpress rest endpoints (my first php yeah!)
1. you need simpleJWT plugin to take care of auth.
2. make sure you enable jwt on all endpoints and pass &jwt=<token>
3. this is not production software! as said i am not a PHP engie (assembler, c, c++, c#, pascal but not php 🙂
4. drop the code in functions.php in your themes folder, again not correct, this is not production software, hope bm comes with official api; below is tested and worksdennis
ParticipantPS: like you lost buddypress, we dont need, was just there for better messages. I am c# engineer, not php, will try to hack a simple wordpress endpoint
dennis
Participantthanks for pointing it out, missed that disconnect from buddypress, like. However my bot is external and not within wordpress itself. Is there another an endpoint? url I can abuse?
dennis
Participantok, short update, due to other priorities put this on hold for a while. Via the endpoints from buddypress managed to add ads to the group chats every so many seconds. works great. its still pretty unclear to me what the user_id, thread_id, etc actually mean for better messages, can’t seem to confirm it has something to do with which chatroom, just cant get my finger behind it, can you confirm what the parameters mean in context of better messages?
Current code works but really rough
Message p = new Message
{
recipients = 1,
sender_id = item.UserId, //, //1
Id = 1, // 1, // user id??
thread_id = 0, //??
message = HTMLTools.CreateChatImgTag(Media.Url, “”)
};var Chats = await wpclient.CustomRequest.UpdateAsync<Message, dynamic>(“buddypress/v1/messages”, p);
dennis
ParticipantHi,
Again stunned by your support however how to put this message in a specific chat window? should i use thread id for that or something?Regards,
Dennisdennis
Participantok, awesome support! thanks for the quick message. please consider it for the future.
-
AuthorPosts