# Creating bot on discourse

**URL:** https://meta.discourse.org/t/creating-bot-on-discourse/224822
**Category:** Development
**Created:** [April 20, 2022, 7:52am UTC](https://meta.discourse.org/t/creating-bot-on-discourse/224822 "2022-04-20T07:52:10Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![seeminglee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/seeminglee/32/199310_2.png) [@seeminglee](https://meta.discourse.org/u/seeminglee)
#### Post date: [April 20, 2022, 7:52am UTC](https://meta.discourse.org/t/creating-bot-on-discourse/224822/1 "2022-04-20T07:52:10Z")

</div>

Is there a way to create a bot on Discourse that would reply to my commands, in a similar way that I have built many of my Discord bots?

Basically, I know that there are various plugins that I can install, but in my mind, it would be far easier for me to maintain if I could just have a bot that could listen to the text in a comment rather than trying to install plugins that are prone to mess up with things and especially if the maintainer decides that they don’t want to maintain the plugin anymore.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [April 20, 2022, 8:21am UTC](https://meta.discourse.org/t/creating-bot-on-discourse/224822/2 "2022-04-20T08:21:04Z")

</div>

You are going to need a plugin.

Take a look at my Frotz plugin as an example/starting point

> [@Discourse Frotz mage](https://meta.discourse.org/t/discourse-frotz-an-interactive-fiction-game-bot/140617):
>
> Wooah, a new plugin! tada This one is a little less serious, though. video_gameDiscourse Frotz [[image] ](https://global.discourse-cdn.com/meta/original/3X/4/7/477f2c8c14006fa019eea94d4ba9bd95b7259412.png) It’s no longer necessary to @ mention the bot every step of the way. Once in play, just reply to it. Git repo: [GitHub - merefield/discourse-frotz: A plugin that uses Frotz to give you an interactive fiction experience on your Discourse forum · GitHub](https://github.com/merefield/discourse-frotz)What is it It’s a ‘bot’ with which to play interactive fiction aka classic text adventure …

API only plugins like this tend to be more stable over time so don’t worry about instability. All code requires maintenance in any case. I’ve done minimal changes to Frotz-bot over time.

Take a look at my Discord bot plugin to see how you can write code against events like new posts:

> [@Discord Bot Construction Kit robot](https://meta.discourse.org/t/discord-bot-construction-kit/122530):
>
> Purpose of this plugin This plugin does several things: Allows you to power a Discord bot using your Discourse server to do stuff to link the two systems. Fork this repo and expand it with simple Ruby to create all kinds of bot functionality. Existing functionality to serve as examples and useful utility: Provides some two-way auto posting of content that meet some criteria. Command to copy messages ad hoc to Discourse Command to sync group membership to role membership of your Discor…

Your needs might be met by:

> [@Discourse Automation](https://meta.discourse.org/t/discourse-automation/195773):
>
> discourse2Summary Discourse Automation lets you automate actions through scripts and triggers. Customisation is made through an automatically generated UI.open_bookInstall Guide This plugin is bundled with Discourse core. There is no need to install the plugin separately. Features Easy automation of complex workflows Triggers automations at specific dates, periodically, or on specific events Provides automatically generated UIs…

If you want more control over the code’s destiny, maintain a fork/repo yourself.

---

<div class="post-metadata">

### Author: ![Simon\_Manning](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon_manning/32/198596_2.png) [@Simon\_Manning](https://meta.discourse.org/u/Simon_Manning)
#### Post date: [April 20, 2022, 1:42pm UTC](https://meta.discourse.org/t/creating-bot-on-discourse/224822/3 "2022-04-20T13:42:19Z")

</div>

If you really want it to be entirely separate, you could use a combination of webhooks to deliver events to your bot and the HTTP requests API to have your bot make changes in Discourse.

> [@Configure webhooks that trigger on Discourse events to integrate with external services](https://meta.discourse.org/t/setting-up-webhooks/49045):
>
> A webhook is a way to notify external services about changes on the internet. It’s easier to setup, manage and develop than a Discourse plugin. Though, it does require you to program a little bit or understand its technical details. In this #howto, I’ll set up webhook to power a Github bot for referencing pull request brought in a forum. We’ll want to see a new comment on Github pull request when a new post has a link to it. It’s a very simple process: Publish a new post. A webhook event happ…

[Discourse API Docs](https://docs.discourse.org/)

As @merefield alludes to though, it is possible to create plugins that do not override core functionality, instead being notified for events and interacting with core APIs, which are easier to maintain and less likely to have unwanted side effects.

Going the webhook/API route also requires setting up a stack to run your bot and ensuring that it is always available while Discourse is available, both of which come for free with a plugin loaded into Discourse.

Writing a plugin would require learning Ruby and gaining some familiarity with Discourse classes but if you’re already capable of writing and maintaining a bot in something else, I’m sure you could learn what’s needed pretty quickly.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [April 20, 2022, 1:43pm UTC](https://meta.discourse.org/t/creating-bot-on-discourse/224822/4 "2022-04-20T13:43:35Z")

</div>

> [@Simon\_Manning](#):
>
> If you really want it to be entirely separate, you could use a combination of webhooks to deliver events to your bot and the HTTP requests API to have your bot make changes in Discourse.

Ah yes, that too, good point Simon!

---

<div class="post-metadata">

### Author: ![seeminglee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/seeminglee/32/199310_2.png) [@seeminglee](https://meta.discourse.org/u/seeminglee)
#### Post date: [April 21, 2022, 8:38am UTC](https://meta.discourse.org/t/creating-bot-on-discourse/224822/5 "2022-04-21T08:38:11Z")

</div>

Thank you everyone for your suggestions — I will definitely take look at all of them. 😃

---

<div class="post-metadata">

### Author: ![fbpbdmin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fbpbdmin/32/300893_2.png) [@fbpbdmin](https://meta.discourse.org/u/fbpbdmin)
#### Post date: [October 24, 2023, 5:54am UTC](https://meta.discourse.org/t/creating-bot-on-discourse/224822/6 "2023-10-24T05:54:26Z")

</div>

this can be done in the post/comment,

is it possible to have a bot in a group chat ?  
I see there is incoming webhook that could deliver message to a groupchat,  
but seems there is no way having a bot account that listens to the chat messages, then do something accordingly… ?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [October 24, 2023, 6:49am UTC](https://meta.discourse.org/t/creating-bot-on-discourse/224822/7 "2023-10-24T06:49:28Z")

</div>

Yes, for example:

> [@Discourse Chatbot robot](https://meta.discourse.org/t/discourse-chatbot-now-smarter-than-chatgpt/256652):
>
> information_sourceSummary The Original AI Chatbot for Discoursehammer_and_wrenchRepository Link [GitHub - merefield/discourse-chatbot: An AI bot with RAG capability for Topics, Chat & Customer Support in Discourse, currently powered by OpenAI · GitHub](https://github.com/merefield/discourse-chatbot)open_bookInstall Guide [How to install plugins in Discourse](https://meta.discourse.org/t/install-plugins-in-discourse/19157)heartSponsorship Please consider becoming an ongoing [sponsor of my open source work](https://github.com/sponsors/merefield) at a level that suits your or your organisation’s resources and needs to ens…

supports Group chat (as well as Topics, PMs …)

(This is a purely AI bot without commands (the interface is 100% natural language so this is not required) but the structure would be the same)

---

<div class="post-metadata">

### Author: ![fbpbdmin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fbpbdmin/32/300893_2.png) [@fbpbdmin](https://meta.discourse.org/u/fbpbdmin)
#### Post date: [October 24, 2023, 3:11pm UTC](https://meta.discourse.org/t/creating-bot-on-discourse/224822/8 "2023-10-24T15:11:38Z")

</div>

thanks @merefield

with a plugin, it could add an event hander/listener for group chat message.  
I have a rest endpoint server that handles the webhook events, that works nicely for adding a bot to the post/comment.  
but unfortunately, there is no events fired for group chat message, it does not fly that way… ☹
