diff --git a/changelog/5250.enhancement.rst b/changelog/5250.enhancement.rst new file mode 100644 index 000000000000..a4b429a643eb --- /dev/null +++ b/changelog/5250.enhancement.rst @@ -0,0 +1 @@ +Added support for mattermost connector to use bot accounts. \ No newline at end of file diff --git a/docs/user-guide/connectors/mattermost.rst b/docs/user-guide/connectors/mattermost.rst index 95a88046b795..fedc5476a07e 100644 --- a/docs/user-guide/connectors/mattermost.rst +++ b/docs/user-guide/connectors/mattermost.rst @@ -12,6 +12,14 @@ Once you have them you can add these to your ``credentials.yml``. Getting Credentials ^^^^^^^^^^^^^^^^^^^ +Mattermost now uses bot accounts for better security. So you can use their guide to create +your bot to get your token required for the `credentials.yml` file. + +For more information on creating a bot account please see +`Bot Creation `_. + +For information on converting existing user account into bot account please see +`User Conversion `_. **How to set up the outgoing webhook:** @@ -50,8 +58,7 @@ you need to supply a ``credentials.yml`` with the following content: mattermost: url: "https://chat.example.com/api/v4" team: "community" - user: "user@user.com" # actual username of your bot user, not displayname - pw: "password" + token: "xxxxx" # the token for the bot account from creating the bot step. webhook_url: "https://server.example.com/webhooks/mattermost/webhook" The endpoint for receiving Mattermost channel messages diff --git a/rasa/core/channels/mattermost.py b/rasa/core/channels/mattermost.py index c9f71c43d3e3..8310ba0f620e 100644 --- a/rasa/core/channels/mattermost.py +++ b/rasa/core/channels/mattermost.py @@ -28,20 +28,17 @@ def __init__( self, url: Text, team: Text, - user: Text, - pw: Text, + token: Text, bot_channel: Text, webhook_url: Optional[Text], ) -> None: self.url = url self.team = team - self.user = user - self.pw = pw + self.token = token self.bot_channel = bot_channel self.webhook_url = webhook_url - super().__init__(url, team) - super().login(user, pw) + super().__init__(url, team, token=token) async def send_text_message( self, recipient_id: Text, text: Text, **kwargs: Any @@ -120,15 +117,12 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne return cls( credentials.get("url"), credentials.get("team"), - credentials.get("user"), - credentials.get("pw"), + credentials.get("token"), credentials.get("webhook_url"), ) # pytype: enable=attribute-error - def __init__( - self, url: Text, team: Text, user: Text, pw: Text, webhook_url: Text - ) -> None: + def __init__(self, url: Text, team: Text, token: Text, webhook_url: Text) -> None: """Create a Mattermost input channel. Needs a couple of settings to properly authenticate and validate messages. @@ -137,16 +131,14 @@ def __init__( url: Your Mattermost team url including /v4 example https://mysite.example.com/api/v4 team: Your mattermost team name - user: Your mattermost userid that will post messages - pw: Your mattermost password for your user + token: Your mattermost bot token webhook_url: The mattermost callback url as specified in the outgoing webhooks in mattermost example https://mysite.example.com/webhooks/mattermost/webhook """ self.url = url self.team = team - self.user = user - self.pw = pw + self.token = token self.webhook_url = webhook_url async def message_with_trigger_word( @@ -165,12 +157,7 @@ async def message_with_trigger_word( try: out_channel = MattermostBot( - self.url, - self.team, - self.user, - self.pw, - self.bot_channel, - self.webhook_url, + self.url, self.team, self.token, self.bot_channel, self.webhook_url, ) user_msg = UserMessage( text, @@ -198,12 +185,7 @@ async def action_from_button( try: out_channel = MattermostBot( - self.url, - self.team, - self.user, - self.pw, - self.bot_channel, - self.webhook_url, + self.url, self.team, self.token, self.bot_channel, self.webhook_url, ) context_action = UserMessage( action, diff --git a/requirements.txt b/requirements.txt index bafda9be64aa..82946ea92cd5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,7 +27,7 @@ slackclient==1.3.1 python-telegram-bot==11.1.0 twilio==6.26.3 webexteamssdk==1.1.1 -mattermostwrapper==2.1 +mattermostwrapper==2.2 rocketchat_API==0.6.31 colorhash==1.0.2 pika==1.0.1 diff --git a/tests/core/test_channels.py b/tests/core/test_channels.py index 4570f756eb2d..b61035b54c16 100644 --- a/tests/core/test_channels.py +++ b/tests/core/test_channels.py @@ -211,10 +211,9 @@ def test_mattermost_channel(): url="http://chat.example.com/api/v4", # the name of your team for mattermost team="community", - # the username of your bot user that will post messages - user="user@email.com", + # the bot token of the bot account that will post messages + token="xxxxx", # the password of your bot user that will post messages - pw="password", # the webhook-url your bot should listen for messages webhook_url="YOUR_WEBHOOK_URL", )