Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating mattermost connector to use bot accounts #5250

Merged
merged 13 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/5250.enhancement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for mattermost connector to use bot accounts.
11 changes: 9 additions & 2 deletions docs/user-guide/connectors/mattermost.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://docs.mattermost.com/developer/bot-accounts.html#bot-account-creation>`_.

For information on converting existing user account into bot account please see
`User Conversion <https://docs.mattermost.com/developer/bot-accounts.html#how-do-i-convert-an-existing-account-to-a-bot-account>`_.

**How to set up the outgoing webhook:**

Expand Down Expand Up @@ -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"
btotharye marked this conversation as resolved.
Show resolved Hide resolved
user: "[email protected]" # 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
Expand Down
36 changes: 9 additions & 27 deletions rasa/core/channels/mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down