Save chat information between users?


  • @a_5mith ok thank you

  • Admin

    Not sure if I get what you mean. Record as in save a history in the ACP for the admin to troll over? In any case I imagine it should be as easy as adding an action hook into the chat method and going from there


  • @psychobunny yeah and maybe record some statistics like how many times user1 has messaged user2. I'm new to NodeBB but I would love to implement it into one of my programs as I think it would be a great fit. Do you mind elaborating a bit more on how I would go about adding an action hook into the chat method?

  • Admin

    Seems like there's already a hook 😉

    filter:messaging.save

    found at https://github.com/NodeBB/NodeBB/blob/851d5c0f32981ffed5ad55cb2f3cc4e5a1cef8cb/src/messaging.js#L37

    Your plugin would just have to listen to that hook. The message object contains fromuid, touid, timestamp, and content, pretty much everything you'd need to write a decent enough analytics plugin 👍

    EDIT: we have a plugin contest coming up soon, perhaps you'd want to register and try your luck 😉


  • @psychobunny thank you!! 🙂


  • @psychobunny I can't seem to get it working, do you mind helping me a bit? I followed this tutorial and got the library.js file to print out "hello, world!" as soon as the plugin is loaded. But after I try adding the "filter:messaging.save" hook into the plugin.json file, "hello, world!" never gets printed. Here are my library.js and plugin.json files:

    plugin.json
    {
    "id": "nodebb-plugin-test",
    "name": "NodeBB Messaging Stats Plugin",
    "description": "NodeBB testing Plugin",
    "url": "https://github.com/psychobunny/nodebb-plugin-youtube",
    "library": "./library.js",
    "hooks": { "hook": "filter:messaging.save", "method": "myMethod"}
    }

    library.js
    var MyPlugin = {

    myMethod: function(message, next) {
    	//do something with message here
    	console.log('***************hello, world!*****************');
    }
    

    };

    any help will be appreciated, thanks..!

  • Admin

    Does the chat still work as normal?

    EDIT: is that the full library.js file? You're missing the module.exports = MyPlugin line at the bottom


  • @psychobunny Thanks! that's what I was missing. It's working now 🙂
    for anybody interested, here's how my files look now:

    plugin.json

    {
    	"id": "nodebb-plugin-youtube",
    	"name": "NodeBB YouTube Plugin",
    	"description": "NodeBB Plugin that allows users to embed YouTube videos inline in their posts.",
    	"url": "https://github.com/psychobunny/nodebb-plugin-youtube",
    	"library": "./library.js",
    	"hooks": [
    		{ "hook": "filter:messaging.save", "method": "myMethod", "callbacked": true, "priority": 6 }
    	]
    }
    

    library.js

    (function(module) {
    	"use strict";
    
    	var myPlugin = {};
    	myPlugin.myMethod = function(message, callback) {
    		console.log(message.content);
    
    		callback(null, message);
    	};
    
    	module.exports = myPlugin;
    }(module));
    

    @psychobunny I'll look into that plugin contest even though, I'm extremely new to NodeBB and only have basic JavaScript skills! 😄


  • This would make for an interesting plugin. While I dont agree with admins browsing user chats, sometimes it can be necessary to settle disputes.


  • @Ted yeah, and also the way I'm using the chat is not necessarily for casual conversations; statistics/logs from chat are needed 🙂

Suggested Topics

| |