I want to create a chat bot in Mattermost. A human user can send a direct message to the bot to start a conversation. The AI logic for the bot will reside in an external application.
After searching through the Mattermost docs, I thought that using an App is the most suitable option, since it comes with a corresponding bot account - Apps
“2. External (HTTP) Apps. Apps can be hosted as publicly (or privately) available HTTP services, the choice of hosting provider is yours. A self-managed Mattermost customer would be able to install your App from a URL”
I referred to the sample apps provided on GitHub - mattermost/mattermost-app-examples: Examples for the Mattermost App Framework
and created my own
Then I was able to add the app to a Mattermost server hosted locally using the following command -
/apps install http http://172.17.0.1:4675/mattermost/manifest.json
I used the following manifest.json file
{
"app_id":"testing",
"version":"v1.2.0",
"homepage_url":"http://172.17.0.1:4675/mattermost/homepage.html",
"display_name":"Testing",
"icon":"icon.png",
"requested_permissions":["act_as_bot","act_as_user"],
"requested_locations":["/channel_header","/command"],
"http":{"root_url":"http://172.17.0.1:4675/mattermost"}
}
And the following bindings file
{
"type": "ok",
"data": [
{
"location": "/channel_header",
"bindings": [
{
"location": "send-button",
"icon": "icon.png",
"label": "send hello message",
"form": {
"title": "Hello, world!",
"icon": "icon.png",
"submit": {
"path": "/send",
"expand": {
"acting_user": "id",
"acting_user_access_token": "all"
}
},
"fields": [
{
"name": "Message",
"type": "text"
}
]
}
}
]
},
{
"location": "/command",
"bindings": [
{
"icon": "icon.png",
"label": "helloworld",
"hint": "[send]",
"description": "Hello World app",
"bindings": [
{
"label": "send",
"form": {
"title": "Hello, world!",
"icon": "icon.png",
"submit": {
"path": "/send",
"expand": {
"acting_user": "id",
"acting_user_access_token": "all"
}
},
"fields": [
{
"name": "Message",
"type": "text"
}
]
}
}
]
}
]
}
]
}
Note: the above are only slight modifications from the examples provided on GitHub - mattermost/mattermost-app-examples: Examples for the Mattermost App Framework
However, with this setup, I do not receive any messages to my app when a user sends a message to the app’s bot. It is unclear to me from the docs how I can subscribe to receiving an event (with the user’s text) when the user sends a direct message to the bot.