Mattermost Channel debugging

I have a Mattermost site running locally and exposed at localhost:8065. I have a Rasa instance running rasa run --debug locally as well, exposed as localhost:5005. I created an outgoing webhook in Mattermost according to your doc at: https://rasa.com/docs/rasa/user-guide/connectors/mattermost/#getting-credentials and set the Callback URL to http://localhost:5005/webhooks/mattermost/webhook. Does that mean I need to edit the credentials.yml, mattermost section to look like:

mattermost:
  url: "http://localhost:8065/hooks/xx615yapapbipeqyqtn3xasc4a"
  team: "Groupname"
  user: "Username"
  pw: "********"

Where the url is the outgoing webhook with it’s token. Also had to AllowUntrustedInternalConnections to 127.0.0.1/8

I’m getting

2019-10-10 15:23:46 ERROR    rasa.core.channels.mattermost  - Exception when trying to handle message.'token'
2019-10-10 15:23:46 DEBUG    rasa.core.channels.mattermost  - 'token'
Traceback (most recent call last):
  File "c:\programdata\anaconda3\envs\rasa\lib\site-packages\rasa\core\channels\mattermost.py", line 98, in webhook
    self.url, self.team, self.user, self.pw, self.bot_channel
  File "c:\programdata\anaconda3\envs\rasa\lib\site-packages\rasa\core\channels\mattermost.py", line 27, in __init__
    super(MattermostBot, self).login(user, pw)
  File "c:\programdata\anaconda3\envs\rasa\lib\site-packages\mattermostwrapper\wrapper.py", line 39, in login
    self.token = p.headers["Token"] # Store the token for further requests
  File "c:\programdata\anaconda3\envs\rasa\lib\site-packages\requests\structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'token'

and no response from the bot.So something is being sent to rasa (I’m trying to find the exact json) and rasa is choking on it.

So I can try to take a look at this, I wrote the mattermost wrapper that is used but I also haven’t updated it in a while so this could be related to Mattermost updates as well.

Give me a few days and I’ll test my wrapper code to ensure it isn’t the issue here either. I’m assuming you never have had this working yet?

Thanks

Thank you. The logs appear to indicate that Rasa is receiving some input from the webhook, but is unable to interpret it. Any tips for debugging that I can do on my own?

Nothing immediately comes to mind I haven’t tested out the mattermost wrapper I wrote in a while so its very possible something has changed. I just need to get my server up again and test it.

Is there some more setup to do? I have setup a debug environment in Pycharm and with Postman I can call and trace a GET /webhooks/rest and a POST to /webhooks/rest/webhook. But a similar call to GET /webhooks/mattermost does not get to

        @mattermost_webhook.route("/", methods=["GET"])
        async def health(_: Request) -> HTTPResponse:
            return response.json({"status": "ok"})

in /rasa/core/channels/mattermost.py I get

Error: Requested URL /webhooks/mattermost not found

as the 404 response in Postman.

It’s acting like requests are not dispatched to the mattermost handler.

Hey @Charlesjwilliams2,

So I tested my wrapper and it still works fine here is how I setup my bot and as you can see from the screenshot it works.

I just spun up the basic docker mattermost via:

docker run --name mattermost-preview -d --publish 8065:8065 mattermost/mattermost-preview - Now I have a instance running at whatever my ip/localhost:8065

Then I created the outgoing webhook (I’m also going to look into these new bot account options they have soon) with the following callback url, I just used my ip of my machine:

http://192.168.1.79:5005/webhooks/mattermost/webhook

Made sure I set it up like you mentioned to be a trusted connection in the System Console/Developer section with 192.168.1.0/24

Then my crendentials.yml file looked like this:

rest:

rasa:
  url: "http://localhost:5002/api"

mattermost:
  url: "http://localhost:8065/api/v4"
  team: "testing"
  user: "whatever@domain.com"
  pw: "testing123!"

And it worked fine for me using Rasa 1.3.9

So not sure where this token error is coming from but I don’t think its the connector

Ok. I configured my Rasa environment to match yours above and got the debugger working so I can trace through the mattermost connection. It turned out that I wasn’t invoking the debugger with the --credentials switch. Now I can trace the code from the log:

2019-10-17 11:54:36 ERROR    rasa.core.channels.mattermost  - Exception when trying to handle message.'token'
2019-10-17 11:54:36 DEBUG    rasa.core.channels.mattermost  - 'token'
Traceback (most recent call last):
  File "C:\Users\willic38\Documents\rasa\rasa\rasa\core\channels\mattermost.py", line 173, in message_with_trigger_word
    self.webhook_url,
  File "C:\Users\willic38\Documents\rasa\rasa\rasa\core\channels\mattermost.py", line 44, in __init__
    super(MattermostBot, self).login(user, pw)
  File "C:\ProgramData\Anaconda3\envs\rasa\lib\site-packages\mattermostwrapper\wrapper.py", line 39, in login
    self.token = p.headers["Token"] # Store the token for further requests
  File "C:\ProgramData\Anaconda3\envs\rasa\lib\site-packages\requests\structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'token'

It looks like it’s failing to login. The POST is returning a 401.

It’s the user and password for an input webhook.

Ok. My bad. I was using the display name for the user instead of the email format user name. After correcting the credentials.yml, I now get:

So this wasn’t all a total waste. I have figured out how to debug rasa in Pycharm and you can close this ticket. I will try and follow up with an article with the important points for setting up the debug environment.

Ok great I’m gonna update those docs a little bit as well to be more clear

Hi charles
i have some issue when intergrate rasabot with mattermost. it alway return log is connection refuse. Can you help me
This is my setting. i cannot understand why my bot cannot connect

@btotharye Can you help me about under issue

I’m sorry which issue @vunt39 this thread has a lot going on in it. Might even be best to start a new thread with your issue.

I have responded to your thread I believe it is because you have the webhook_url commented out in that screenshot.

oh. i’m sorry. Because of i see your example that it have no webhook_url so i commented out that line. But now everything it’s ok. i have some problem with the ip in docker. i spent many time on it with the support from my partners.
Thank you so much for reply

What was the solution out of curiosity to get it working for you?

oh i just config the webhook url with the ip inside docker. in this case that cannot be the localhost and i have to go inside docker and find. finally it worked