This should work moderately well for communities that desire bot integrations. There are a few gotchas (see the readme) but for the most part it has been pretty incredible to tinker with so far.
Something my community desired was a dice roller, which I knew existed as a hubot plugin. While there have been other attempts at integrating dice rollers into discourse, if I was going to run a bot against my Discourse instance, I wanted the full power of hubot plugins at my disposal. My aim here was to have there be an easy way to integrate such reply features into a Discourse community using an existing and well known bot.
This adapter is about adding a bot that directly listens in to topics and replies in Discourse itself. It differs from a previous Hubot integration topic as that seemed to be aimed at querying a discourse community in an existing integration (irc, slack, etc) to get discourse stats, and possibly post to a remote Discourse instance.
The bot now polls for messages over Discourseās message bus.
I created the repository as hubot-discourse-integration, as hubot-discourse was already takenā¦ Sadly this also had no documentation, code, or announcements here. I wasnāt inclined to trust it, so I built this.
Ah right, thanks for the tip! Iāll look into that today ā Iāve been putting off learning more about the message bus in general, just to get things working.
Alright, I have practically torn apart your message-bus javascript client and adapted it for node and itās working great! Polling is now done over message bus, so it should be a lot more responsive now!
One more question - Is there any way for me to get the current user, given a user API key? It would be great if a 3rd party app could figure out their own username + id without having to configure it separately.
Hubot can be configured with both pre-written plug-in scrips, as well as ad-hoc scripts. You can get started with hubot pretty quickly over commandline for local barebones testing of responses. This adapter is only here to allow it to āspeakā and respond over discourse.
You can set it up that way - The adapter responds via discourseās native notifications. Basically, if thereās a discourse notification of a message, the bot will see it. In the botās Discourse profile, you can edit and add to the watched categories to allow it to automatically see new topics/replies/etc without a direct @.
EG: for your use case, you would probably want to add your interested categories to āwatching first postā and set the āwhen I post in a topic set that topic toā normal. That way, the bot gets notified on new topics, but does not continue to monitor/reply afterwards.
Not currently - It follows the same patterns from other hubot adapters - aside from setting up what hubot āhearsā in discourse, you really shouldnāt have to mind much about the internals. Mostly youād be interested in the API, and the difference between function hooks like robot.hear vs robot.respond. See the docs for examples!
Thanks for replying, will take a deeper look later.
While reading I got an idea: Can your adapter already send private messages instead of post to topics? āModerating in privateā might be an interesting concept to have to call out the people in public but nudge them to add the information in private.
Not currently; it was out of my use case, but it would be possible to extend/ modify how the bot replies to send private messages rather than replying inline.
Itās admittedly a little bit of a custom workaround as hubot doesnāt currently have a concept of PM replying, so Iām relying on a āpmā attribute to be set in res.envelope to imply that we want the bot to respond privately.
Hereās an example:
robot.hear /private hello/i, (res) ->
res.envelope.pm = true
res.send "I will reply hello privately!"
The new PM is titled āAbout your post in {topic title}ā, and has the first line as the URL to the topic in question.
If the bot is already hearing a message within a PM, it replies as normal.
It would be nice if Hubot had the concept of a whisper, but thatās unfortunately out of my hands at the moment.
I also added the ability to arbitrarily add messages to other topics, or trigger sending of messages by way of the robot.messageRoom action to be able to generate PMs or reply to arbitrary topics by topic number.
Hi @awole20, I got everything set up, thanks a million for this adapter! It works great, but my hubot canāt respond or operate in the chat box made possible by the Babble plugin. https://meta.discourse.org/t/babble-a-chat-plugin/31753
Is there a way to get it working in there? I set the bot to the room but it doesnāt hear/ pick up anything from the chat channel.
Iām assuming you are expecting the bot to respond to an unprompted reply. You need to ābecomeā the bot (admin ā users) and add that topic to āwatchingā as stated above:
I understand that, and I think it sees it but canāt send a message somehow. The problem is that it doesnāt operate like a regular topic, because you canāt āwatchā it. Maybe @gdpelican , the plugin creator, could provide some insight.
Oh I understand now - sorry, I donāt have much experience with the ins and outs of babble, and have not attempted to set up a Hubot to listen in on a Babble install. If Babbleās notification flow is outside of the normal Discourse notifications, that would block your bot from seeing those messages.
I think this is pretty close to working out of the box, but Iām missing some bit of context or code here to get a fix.
This line:
[Tue Mar 06 2018 00:52:11 GMT+0000 (UTC)] INFO got notification: { notification_type: 1,
gets called in hubot-discourse-adapter/discourse.coffee#100, which then calls this.emit with some info.
That info then goesā¦ somewhere (to the script youāve written for your bot?), which is then seemingly creating a post, but not emitting properly to the server (babble operates on a separate message bus channel from regular topics). So the bit that Iām missing is 'where is the code which generates the lines beginning with āEmitting robot action: greetingā?
[Tue Mar 06 2018 00:52:12 GMT+0000 (UTC)] INFO Emitting robot action: greeting, {}
[Tue Mar 06 2018 00:52:12 GMT+0000 (UTC)] INFO Reply { topic_id: 38,
reply_to_post_number: 6,
message: 'How\'s it going?' }
[Tue Mar 06 2018 00:52:12 GMT+0000 (UTC)] INFO Reply { topic_id: 38, reply_to_post_number: 6, message: 'Hi there!' }
So something strange is going on with babbleās handling of replying via the API. Hereās a rundown:
The āemitting robot actionā log there is in his script. Hubot adapters work by āhearingā messages that emit messages to a userās script to handle them (Containing such logic as hearing āhelloā I want to reply with āoh hi thereā). The script has hooks to āreplyā or ārespondā again using the adapterās say or reply method.
Those methods in my adapter simply hook into the Discourse posts.json API endpoint here:
What is the result of that post? It seems to me like the most likely thing thatās happening is that the /posts.json call is creating the post just fine, but that the core Discourse code isnāt able to broadcast to the babble message channel. @Timothy_Vail are you able to figure out whether that /posts.json call actually creates a post or not, and if not, what the response to that request is?
Iāll spin up a babble dev instance soon to dig into the cause of this, and make the bot and plugin be a little more friendly - I think it would be excellent if Babble and Hubot ā both intending to be used as āchatā like features ā played well together.
Sometimes it responds in the chat, but most of the time not. It responded two or three times, but like an hour or more later. In the private messages it was immediate.
So after some testing, it definitely appears that Babbleās message channel doesnāt expect post replies via the API. The response to the /post.json is that itās fine, 200 OK, with the body containing the details of the new post as expected.
I went ahead and installed a test Discourse env with Babble, and wired up a Hubot to communicate with. The Hubot reply posts will show up in the correct order, but only after a refresh. Before that, itās like the bot isnāt saying anything. After refreshing the page, all of Hubotās messages show up in the correct order.
Willing to work with you if Iām able to in order to get this resolved - Iām on the opposite side, where Iām not familiar with Babbleās message notification systems at all.