Mattermost channel configuration

I am trying to configure Mattermost as a channel per instructions found here using Websockets:
https://developer.kore.ai/docs/bots/channel-enablement/adding-the-mattermost-channel/

When I type a greeting in Mattermost such as Hi, the Kore replies with Hello,
The problem is that Kore keeps sending back the Hello greeting in an infinite loop. The only way to stop that is to disable the Mattermost channel and invalidate the access token for Websockets.

The behavior is the same when I type an utterance in Mattermost that matches an intent in a published bot. I just keep getting the same response in an infinite loop from Kore. Has anyone experienced this behavior? Is this a known issue? Is there a fix?

@harshal.mulherkar1
When we test any web-hook channel on https://bots.kore.ai we do not see this issue.
Are you talking about any on-premise installation?
Also, have you used bot-kit in between?

@swagata.sengupta

This is an on-prem installation. I am using Websockets. Webhooks and Botkit SDK are not used in this at all.

Hi @harshal.mulherkar1 ,

It seems like websocket connection is being reset all the time. Which version of bot builder tool are you using?

Also try restarting the listner service once.

Regards,
Karthik

@karthik.tadikonda @swagata.sengupta

We are using v7.2.05 on-prem

Since we are unable so far to get Mattermost channel to work using websockets, we tried using webhooks configuration. But that is not working either. When the user sends a message from Mattermost, an error is reported in the Mattermost logs:

2020-06-08T13:10:26.208-0400 error app/webhook.go:110 Event POST failed. {"error": "Post http://kore-va-poc-rnd.pncint.net/hooks/mattermost/st-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx: address forbidden, you may need to set AllowedUntrustedInternalConnections to allow an integration access to your internal network"}

In Mattermost config.json there is a AllowedUntrustedInternalConnections parameter where we added the Kore server hostname. Is there a similar configuration on the Kore server to add the Mattermost server hostname as a trusted host?

From the Kore server I can send a message to Mattermost webhooks URL using curl

curl -i -X POST -H ‘Content-Type: application/json’ -d ‘{“text”: “Hello, this is a message from Kore VA”}’ https://chatmatters-rnd.pncint.net/hooks/xxxxxxxxxxxxxxxxxxxxxxxxxx

However Kore is not receiving any messages from Mattermost over webhooks.

@harshal.mulherkar1
Just in case you missed, please ensure all channels are published.

@harshal.mulherkar1

Just an update. We just tested that Mattermost channel on an existing bot is working fine.
image

General format for any webhook channel is this

curl --location --request POST 'https://bots.kore.ai/chatbot/hooks/st-5XXXXXXXXXXX2-5a69-b4c6-0904a0cde8a1' \
--header 'Authorization: bearer eyJhbGXYZ' \
--header 'Content-Type: application/json' \
--header 'Content-Type: text/plain' \
--data-raw '{
       "message":{
   		"text" : "Hello"
   	},
       "from" :{
           "id": "<UNIQUE ID>"
   	},
       "to" :{
           "id": "<BOT ID>"

   	}
}

'

Also, we recommend you to check with your internal team about any certificate etc. as AllowedUntrustedInternalConnections is not a known setting from channel perspective at Kore’s end.

Since your installation is on-premise, you may need to whitelist mattermost IP to reach Kore.ai server.

@swagata.sengupta
In the above curl example, where did you get the bearer token from?
–header ‘Authorization: bearer eyJhbGXYZ’

This is a JWT. I obfuscated my JWT. You need to use client id and secret to generate JWT. Refer to jwt.io Use the client id and secret from the app you use to create channel.

image

@swagata.sengupta
My bot uses only a single channel, which is Mattermost. I do not have any other channel. Therefore there is not client ID and client secret. Do I need to add a web channel to my bot as well to be able to use the Mattermost channel?

@harshal.mulherkar1
I had sent you the generic format for webhook channel. For webhook channel you will need an app. I was just answering to your question on where I got the bearer roken from. For just matermost you need not have any app.

Please see if the below from our response helps you.

Also, we recommend you to check with your internal team about any certificate etc. as AllowedUntrustedInternalConnections is not a known setting from channel perspective at Kore’s end.

Since your installation is on-premise, you may need to whitelist mattermost IP to reach Kore.ai server.

Is there anyone from Kore.ai who is currently working with you (on your PoC / current scope of work)?

@swagata.sengupta
Aayush, Karthik and Markkannu are aware of this.

I tried your curl example on my other bot that is published on the web channel, and I could interact with that bot successfully using curl.

Is there a way I could test my bot that is exposed to mattermost channel using curl? The callback URL format is:
http://kore-va-poc-rnd.pncint.net/hooks/mattermost/st-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

However I do not have a client ID and client secret to generate the JWT token

@harshal.mulherkar1
We are investigating further. The bot should respond fine in public room with personal token when you tag the bot.
We will update you on the findings.

@swagata.sengupta

I am trying to pass user ID (or email address) to a published bot through a JWT token.

I have a JWT token for a published bot. The payload data within the JWT token contains a client ID for the bot and an email address identifying the user.
{
“sub”: "harshal.mulherkar@pnc.com",
“appId”: “cs-12345555-abcd-0123-4567-abcdefghijkl”;
}

I can invoke the bot using a curl command and passing the JWT bearer token. The bot responds with the below message service:

print(JSON.stringify(context));

I expect to see the email address embedded within the JWT token somewhere within the context output. However I do not see the email address anywhere within the context. So how do I access the payload information within the JWT token from my bot?