• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Automatically rewrite text matching a regular expression into a markdown link.

Autolink Plugin

Build Status Code Coverage Release HW

Maintainer: @levb Co-Maintainer: @iomodo

This plugin creates regular expression (regexp) patterns that are reformatted into a Markdown link before the message is saved into the database.

Use it to add custom auto-linking on your Mattermost system, such as adding links to your issue tracker based on the regexp patterns.

image

Posting a message containing a Jira issue key..

image

..automatically links to the corresponding issue in the Jira project

Configuration

  1. Go to System Console > Plugins > Management and click Enable to enable the Autolink plugin.

  2. Modify your config.json file to include the types of regexp patterns you wish to match, under the PluginSettings. See below for an example of what this should look like.

Tip: There are useful Regular Expression tools online to help test and validate that your formulas are working as expected. One such tool is Regex101 . Here is an example Regular Expression to capture a post that includes a VISA card number - which you could then obfuscate with the Pattern so people don't accidentally share sensitive info in your channels.

Usage

Autolinks have 3 parts: a Pattern which is a regular expression search pattern utilizing the Golang regexp library, a Template that gets expanded and an optional Scope parameter to define which team/channel the autolink applies to. You can create variables in the pattern with the syntax (?P<name>...) which will then be expanded by the corresponding template.

In the template, a variable is denoted by a substring of the form $name or ${name}, where name is a non-empty sequence of letters, digits, and underscores. A purely numeric name like $1 refers to the submatch with the corresponding index. In the $name form, name is taken to be as long as possible: $1x is equivalent to ${1x}, not ${1}x, and, $10 is equivalent to ${10}, not ${1}0. To insert a literal $ in the output, use $$ in the template.

The scope must be either a team (teamname) or a team and a channel (teamname/channelname). Remember that you must provide the entity name, not the entity display name. Since Direct Messages do not belong to any team, scoped matches will not be autolinked on Direct Messages. If more than one scope is provided, matches in at least one of the scopes will be autolinked.

Below is an example of regexp patterns used for autolinking at https://community.mattermost.com, modified in the config.json file:

"PluginSettings": {
    ...
    "Plugins": {
        "mattermost-autolink": {
            "links": [
                {
                    "Pattern": "(LHS)",
                    "Template": "[LHS](https://docs.mattermost.com/process/training.html#lhs)",
                    "Scope": ["team/off-topic"]
                },
                {
                    "Pattern": "(RHS)",
                    "Template": "[RHS](https://docs.mattermost.com/process/training.html#rhs)",
                    "Scope": ["team/town-square"]
                },
                {
                    "Pattern": "(?i)(Mana)",
                    "Template": "[Mana](https://docs.mattermost.com/process/training.html#mana)"
                },
                {
                    "Pattern": "(?i)(ESR)",
                    "Template": "[ESR](https://docs.mattermost.com/process/training.html#esr)"
                },
                {
                    "Pattern": "((?P<level>0|1|2|3|4|5)/5)",
                    "Template": "[${level}/5](https://docs.mattermost.com/process/training.html#id8)"
                },
                {
                    "Pattern": "(MM)(-)(?P<jira_id>\\d+)",
                    "Template": "[MM-${jira_id}](https://mattermost.atlassian.net/browse/MM-${jira_id})"
                },
                {
                    "Pattern": "https://pre-release\\.mattermost\\.com/core/pl/(?P<id>[a-zA-Z0-9]+)",
                    "Template": "[<jump to convo>](https://pre-release.mattermost.com/core/pl/${id})"
                },
                {
                    "Pattern": "(https://mattermost\\.atlassian\\.net/browse/)(MM)(-)(?P<jira_id>\\d+)",
                    "Template": "[MM-${jira_id}](https://mattermost.atlassian.net/browse/MM-${jira_id})"
                },
                {
                    "Pattern": "https://github\\.com/mattermost/(?P<repo>.+)/pull/(?P<id>\\d+)",
                    "Template": "[pr-${repo}-${id}](https://github.com/mattermost/${repo}/pull/${id})"
                },
                {
                    "Pattern": "https://github\\.com/mattermost/(?P<repo>.+)/issues/(?P<id>\\d+)",
                    "Template": "[issue-${repo}-${id}](https://github.com/mattermost/${repo}/issues/${id})"
                },
                {
                    "Pattern": "(PLT)(-)(?P<jira_id>\\d+)",
                    "Template": "[PLT-${jira_id}](https://mattermost.atlassian.net/browse/PLT-${jira_id})"
                },
                {
                    "Pattern": "(https://mattermost\\.atlassian\\.net/browse/)(PLT)(-)(?P<jira_id>\\d+)",
                    "Template": "[PLT-${jira_id}](https://mattermost.atlassian.net/browse/PLT-${jira_id})"
                }
            ]
        },
    },
    ...
    "PluginStates": {
        ...
        "mattermost-autolink": {
            "Enable": true
        },
        ...
    }
},

Examples

  1. Autolinking Ticket ####:text with alphanumberic characters and spaces to a ticket link. Use:

    • Pattern: (?i)(ticket )(?P<ticket_id>.+)(:)(?P<ticket_info>.*), or if the ticket_id is a number, then (?i)(ticket )(?P<ticket_id>\d+)(:)(?P<ticket_info>.*)
    • Template: [Ticket ${ticket_id}: ${ticket_info}](https://github.com/mattermost/mattermost-server/issues/${ticket_id})
    • Scope: ["teams/committers"] (optional)
  2. Autolinking a link to a GitHub PR to a format "pr-repo-id". Use:

    • Pattern: https://github\\.com/mattermost/(?P<repo>.+)/pull/(?P<id>\\d+)
    • Template: [pr-${repo}-${id}](https://github.com/mattermost/${repo}/pull/${id})
  3. Using autolinking to create group mentions. Use (note that clicking the resulting at-mention redirects to a broken page):

    • Pattern: @customgroup*
    • Template: [@customgroup]( \\* @user1 @user2 @user3 \\* )
  4. For servers with multiple domains (like community and community-daily on the public Mattermost Server), a substitution of absolute conversation links to relative links is recommended to prevent issues in the mobile app. Add one pattern for each domain used:

    • Pattern: https://community\\.mattermost\\.com/(?P\u003cteamname\u003e(?a-zA-Z0-9]+)/(?P\u003cid\u003e[a-zA-Z0-9]+)
    • Template: [<jump to convo>](/${teamname}/pl/${id})/${id})

Autolink the word Handbook to a internal URL on the private team (called office), and a private channel (staff) in the public team (called everyone). - Pattern: (Handbook) - Template: [Handbook](http://www.mywebsite.com/private/handbook) - Scope: ["office", "everyone/staff"]

You can check your pattern with those Regex Testers:

Configuration Management

The /autolink commands allow the users to easily edit the configurations.

Commands Description Usage
list Lists all configured links /autolink list
list <linkref> List a specific link which matched the link reference /autolink list test
test <linkref> test-text Test a link on the text provided /autolink test Visa 4356-7891-2345-1111 -- (4111222233334444)
enable <linkref> Enables the link /autolink enable Visa
disable <linkref> Disable the link /autolink disable Visa
add <linkref> Creates a new link with the name specified in the command /autolink add Visa
delete <linkref> Delete the link /autolink delete Visa
set <linkref> <field> value Sets a link's field to a value
Fields -
  • Template - Sets the Template field
  • Pattern - Sets the Pattern field
  • WordMatch - If true uses the \b word boundaries
  • ProcessBotPosts - If true applies changes to posts made by bot accounts.
  • Scope - Sets the Scope field (team or team/channel or a whitespace-separated list thereof)

/autolink set Visa Pattern (?P<VISA>(?P<part1>4\d{3})[ -]?(?P<part2>\d{4})[ -]?(?P<part3>\d{4})[ -]?(?P<LastFour>[0-9]{4}))

/autolink set Visa Template VISA XXXX-XXXX-XXXX-$LastFour

/autolink set Visa WordMatch true

/autolink set Visa ProcessBotPosts true

/autolink set Visa Scope team/townsquare

Development

This plugin contains a server portion.

Use make dist to build distributions of the plugin that you can upload to a Mattermost server. Use make check-style to check the style. Use make deploy to deploy the plugin to your local server.

For additional information on developing plugins, refer to our plugin developer documentation.

More Repositories

1

mattermost

Mattermost is an open source platform for secure collaboration across the entire software development lifecycle..
TypeScript
30,433
star
2

focalboard

Focalboard is an open source, self-hosted alternative to Trello, Notion, and Asana.
TypeScript
20,596
star
3

mattermost-webapp

Archived web app of Mattermost. Moved to the monorepo: https://github.com/mattermost/mattermost
TypeScript
2,290
star
4

desktop

Mattermost Desktop application for Windows, Mac and Linux
TypeScript
1,921
star
5

mattermost-mobile

Next generation iOS and Android apps for Mattermost in React Native
TypeScript
1,898
star
6

mattermost-docker

Deprecated
Shell
964
star
7

docker

Install Mattermost server via Docker
Shell
320
star
8

mattermost-push-proxy

Go
217
star
9

docs

Mattermost documentation
Python
205
star
10

mattermost-redux

Redux for Mattermost
JavaScript
200
star
11

mattermost-plugin-jitsi

Jitsi plugin for Mattermost ๐Ÿ”Œ
Go
183
star
12

mattermost-android-classic

Mattermost app for Android phones and tablets
Java
175
star
13

mattermost-bot-sample-golang

Go
170
star
14

openops

Open source stack for applying AI to workflows in secure environments
Shell
159
star
15

mattermost-ios-classic

Mattermost iOS application source code
Swift
156
star
16

mattermost-helm

Mattermost Helm charts for Kubernetes
Smarty
153
star
17

mattermost-plugin-gitlab

GitLab plugin for Mattermost
JavaScript
136
star
18

mattermost-plugin-github

GitHub plugin for Mattermost
Go
131
star
19

mattermost-plugin-ai

Mattermost Copilot plugin supporting multiple LLMs
Go
127
star
20

react-native-paste-input

React Native TextInput replacement to allow pasting files
Objective-C
124
star
21

mattermost-operator

Mattermost Operator for Kubernetes
Go
117
star
22

mattermost-plugin-zoom

Zoom plugin for Mattermost ๐Ÿ”Œ
Go
106
star
23

mattermost-plugin-starter-template

Build scripts and templates for writing Mattermost plugins.
Go
98
star
24

mattermost-plugin-jira

JIRA plugin for Mattermost ๐Ÿ”Œ
Go
97
star
25

mattermost-plugin-calls

TypeScript
95
star
26

xml-roundtrip-validator

Go
78
star
27

mattermost-api-reference

Mattermost API reference documentation.
HTML
76
star
28

mattermost-integration-gitlab

GitLab Integration Service for Mattermost
Python
75
star
29

mattermost-plugin-playbooks

Mattermost Playbooks enable reliable and repeatable processes for your teams using checklists, automation, and retrospectives.
TypeScript
72
star
30

mattermost-developer-documentation

Mattermost developer documentation.
CSS
71
star
31

mattermost-data-warehouse

Python
67
star
32

mattermost-cloud

Tools and services for running Mattermost Cloud โ˜๏ธ
Go
67
star
33

mattermost-plugin-demo

A demo of what Mattermost plugins can do.
Go
64
star
34

mattermost-plugin-memes

Add culture to your Mattermost with memes ๐Ÿ”Œ
Go
61
star
35

mattermost-plugin-todo

Mattermost plugin for tracking to do items
JavaScript
60
star
36

mattermost-load-test

[DEPRECATED] replaced by https://github.com/mattermost/mattermost-load-test-ng
Go
59
star
37

mattermost-plugin-welcomebot

Go
57
star
38

mattermost-docker-preview

Mattermost Preview Docker Image
Dockerfile
57
star
39

mattermost-load-test-ng

Mattermost next generation loadtest agent
Go
55
star
40

mattermost-cloud-monitoring

HCL
53
star
41

mattermost-plugins

This project hosts plugins built by Mattermost staff and community.
45
star
42

mattermost-handbook

Mattermost Community and Staff Handbook
44
star
43

mattermost-driver-javascript

Javascript library for interacting with the Mattermost API
JavaScript
42
star
44

action-mattermost-notify

GitHub Action for sending a notification to a Mattermost channel
JavaScript
42
star
45

mattermost-marketplace

The stateless HTTP service backing the Mattermost marketplace.
Go
38
star
46

mattermost-plugin-autotranslate

Go
36
star
47

mattermost-plugin-custom-attributes

Mattermost plugin for adding custom attributes to users!
Go
35
star
48

react-native-network-client

React Native network client by Mattermost
TypeScript
35
star
49

morph

Go
34
star
50

mattermost-plugin-google-calendar

Mattermost Google Calendar Plugin
TypeScript
34
star
51

mattermost-heroku

Run Mattermost on Heroku
Shell
34
star
52

mattermost-plugin-apps

Powers the Mattermost App Framework
Go
33
star
53

mattermost-plugin-antivirus

Antivirus plugin for scanning files uploaded to Mattermost
Go
30
star
54

mattermost-plugin-jenkins

A Mattermost plugin to interact with Jenkins
Go
30
star
55

mattermost-plugin-agenda

Mattermost plugin to handle meeting agendas
Go
29
star
56

mattermost-integration-giphy

Giphy Integration Service for Mattermost
Python
27
star
57

mattermost-interactive-post-demo

Interactive post demo for Mattermost
Python
27
star
58

mattermost-plugin-email-reply

Go
26
star
59

mattermost-ai-framework

The Mattermost AI Framework
TypeScript
26
star
60

rtcd

Go
25
star
61

mattermost-plugin-walltime

Timezone Message Convert for Mattermost ๐Ÿ•› ๐Ÿ•’ ๐Ÿ•• ๐Ÿ•˜
JavaScript
23
star
62

mattermost-webrtc

Dockerfile
22
star
63

mattermost-omnibus

A simple way to install Mattermost.
Go
22
star
64

logr

Fully asynchronous, structured, pluggable logging for Go.
Go
21
star
65

mattermost-plugin-aws-SNS

Plugin that receives SNS notification from Alerts created by AWS CloudWatch and sent via AWS SNS
Go
17
star
66

chewbacca

Chewbacca GitHub Bot
Go
17
star
67

mattermost-browser-extension

Demo Chrome extension for Mattermost 5.2+
JavaScript
16
star
68

mattermost-plugin-skype4business

Go
15
star
69

matterbuild

Matterbuild - An internal Mattermost chatops tool for generating Mattermost releases
Go
14
star
70

mattermost-plugin-docup

Mattermost plugin for marking messages for documentation.
JavaScript
14
star
71

mattermost-govet

Go
14
star
72

quality-assurance

Issues and test assignments for QA Contributors/Community
14
star
73

mattermost-plugin-profanity-filter

A profanity filter plugin.
Go
14
star
74

matrix-as-mm

Matrix โ†”๏ธ Mattermost bridge
PLpgSQL
13
star
75

mattermost-plugin-msteams

MS Teams plugin for Mattermost
Go
13
star
76

mattermost-plugin-mscalendar

Mattermost plugin for Microsoft Office365
Go
13
star
77

mattermost-plugin-confluence

A Mattermost Plugin to receive events from Confluence
Go
13
star
78

mattermost-app-examples

Examples for the Mattermost App Framework
Go
13
star
79

react-native-emm

React Native package for EMM managed configurations
Kotlin
12
star
80

mattermost-plugin-msteams-meetings

Mattermost Plugin for Microsoft Teams Meetings
Go
12
star
81

mattermost-oauth2-client-sample

Sample app for Mattermost OAuth2 and App Center
JavaScript
12
star
82

mattermost-app-zendesk

Zendesk App for Mattermost
TypeScript
11
star
83

dynamic-virtualized-list

Dynamic virtualized list
JavaScript
11
star
84

mattermost-plugin-api

A hackathon project to explore reworking the Mattermost Plugin API.
Go
11
star
85

builder

Mattermost builder
Go
11
star
86

mattermost-mattermod

Go
11
star
87

perseus

Multiplex connections
Go
10
star
88

mattermost-looker

LookML
10
star
89

dbcmp

database comparison tool
Go
10
star
90

mattermost-hackathon-nov2019

10
star
91

mattermost-test-management

Mattermost Test Management, an open testing initiative.
TypeScript
9
star
92

mattermost-plugin-cloud

Go
9
star
93

mattermost-utilities

JavaScript
9
star
94

mattermost-developer-kit

Command line tool for generating Mattermost integration and plugin templates
JavaScript
9
star
95

mmetl

Go
8
star
96

mattermost-plugin-webex

Go
8
star
97

mattermost-plugin-nps

Collect and Send NPS surveys
Go
8
star
98

compass-components

[DEPRECATED] Compass Components is a shared component library used to build appealing user interfaces from scratch with ease. It's based on the Mattermost Design style guide called the Compass Design System.
TypeScript
8
star
99

mattermost-app-nextcloud

Nextcloud App for Mattermost
Go
7
star
100

mattermost-plugin-demo-creator

Go
7
star