HiveMind-mattermost-bridge 0.2.0a3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hivemind_mattermost_bridge-0.2.0a3/HiveMind_mattermost_bridge.egg-info/PKG-INFO +113 -0
- hivemind_mattermost_bridge-0.2.0a3/HiveMind_mattermost_bridge.egg-info/SOURCES.txt +15 -0
- hivemind_mattermost_bridge-0.2.0a3/HiveMind_mattermost_bridge.egg-info/dependency_links.txt +1 -0
- hivemind_mattermost_bridge-0.2.0a3/HiveMind_mattermost_bridge.egg-info/entry_points.txt +2 -0
- hivemind_mattermost_bridge-0.2.0a3/HiveMind_mattermost_bridge.egg-info/requires.txt +11 -0
- hivemind_mattermost_bridge-0.2.0a3/HiveMind_mattermost_bridge.egg-info/top_level.txt +1 -0
- hivemind_mattermost_bridge-0.2.0a3/LICENSE +203 -0
- hivemind_mattermost_bridge-0.2.0a3/PKG-INFO +113 -0
- hivemind_mattermost_bridge-0.2.0a3/mattermost_bridge/__init__.py +159 -0
- hivemind_mattermost_bridge-0.2.0a3/mattermost_bridge/__main__.py +73 -0
- hivemind_mattermost_bridge-0.2.0a3/mattermost_bridge/mmost.py +200 -0
- hivemind_mattermost_bridge-0.2.0a3/mattermost_bridge/version.py +13 -0
- hivemind_mattermost_bridge-0.2.0a3/pyproject.toml +38 -0
- hivemind_mattermost_bridge-0.2.0a3/readme.md +92 -0
- hivemind_mattermost_bridge-0.2.0a3/requirements.txt +4 -0
- hivemind_mattermost_bridge-0.2.0a3/setup.cfg +4 -0
- hivemind_mattermost_bridge-0.2.0a3/tests/test_smoke.py +83 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: HiveMind-mattermost-bridge
|
|
3
|
+
Version: 0.2.0a3
|
|
4
|
+
Summary: Bridge a Mattermost bot account to a HiveMind node
|
|
5
|
+
Author-email: jarbasAI <jarbasai@mailfence.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/JarbasHiveMind/HiveMind_mattermost_bridge
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: hivemind-bus-client<1.0.0,>=0.9.0
|
|
12
|
+
Requires-Dist: mattermostdriver
|
|
13
|
+
Requires-Dist: ovos-utils
|
|
14
|
+
Requires-Dist: ovos-bus-client>=2.0.0a3
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: pytest; extra == "test"
|
|
17
|
+
Provides-Extra: e2e
|
|
18
|
+
Requires-Dist: pytest; extra == "e2e"
|
|
19
|
+
Requires-Dist: hivescope>=0.5.2a1; extra == "e2e"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# HiveMind Mattermost Bridge
|
|
23
|
+
|
|
24
|
+
Relay a [Mattermost](https://mattermost.com) bot account to a [HiveMind](https://github.com/JarbasHiveMind/HiveMind-core) hub.
|
|
25
|
+
|
|
26
|
+
The bridge is a HiveMind **satellite** whose input and output are Mattermost chat instead of a microphone. Mentions and direct messages to the bot become utterances sent to the hub; the hub's spoken reply is posted back to the originating channel. Any HiveMind hub (and the OVOS skills behind it) becomes reachable as a Mattermost chatbot.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
Mattermost channel ⇄ HiveMind_mattermost_bridge ⇄ HiveMind hub ⇄ OVOS skills
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
## Prerequisites
|
|
36
|
+
|
|
37
|
+
- A running **HiveMind hub** ([hivemind-core](https://github.com/JarbasHiveMind/HiveMind-core)) reachable over the network, and a **HiveMind access key** for this bridge (`hivemind-core add-client`).
|
|
38
|
+
- A **Mattermost server** and a **bot user account** on it (an email/login and password the bridge logs in with). The bot must be a member of the channels it should answer in.
|
|
39
|
+
- Python 3.10+.
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
git clone https://github.com/JarbasHiveMind/HiveMind_mattermost_bridge
|
|
45
|
+
cd HiveMind_mattermost_bridge
|
|
46
|
+
pip install .
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This installs the `hivemind-mattermost-bridge` console script.
|
|
50
|
+
|
|
51
|
+
Dependencies: `hivemind-bus-client`, `mattermostdriver`, `ovos-utils`, `ovos-bus-client`.
|
|
52
|
+
|
|
53
|
+
## Quickstart
|
|
54
|
+
|
|
55
|
+
**1. Register the bridge on the hub** (where `hivemind-core` is installed):
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
hivemind-core add-client --name mattermost-bridge \
|
|
59
|
+
--access-key "your-access-key" --password "your-password"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**2. Run the bridge.** Pass Mattermost credentials and HiveMind identity as flags (HiveMind key/password/host default to the values stored by `hivemind-client set-identity`):
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
hivemind-mattermost-bridge \
|
|
66
|
+
--mail bot@example.com \
|
|
67
|
+
--pswd bot-password \
|
|
68
|
+
--url chat.example.com \
|
|
69
|
+
--tag @bot \
|
|
70
|
+
--host ws://127.0.0.1 \
|
|
71
|
+
--port 5678 \
|
|
72
|
+
--key your-access-key \
|
|
73
|
+
--password your-hivemind-password
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Or run as a module: `python -m mattermost_bridge --help`.
|
|
77
|
+
|
|
78
|
+
**3. Send a message.** In a channel the bot is in, mention it:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
@bot what time is it?
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The bridge forwards the message to the hub and posts the hub's reply back to the channel.
|
|
85
|
+
|
|
86
|
+
## Configuration
|
|
87
|
+
|
|
88
|
+
CLI flags (`hivemind-mattermost-bridge --help`):
|
|
89
|
+
|
|
90
|
+
| Flag | Description | Default |
|
|
91
|
+
| --- | --- | --- |
|
|
92
|
+
| `--mail` | Mattermost bot account login (email) | — |
|
|
93
|
+
| `--pswd` | Mattermost bot account password | — |
|
|
94
|
+
| `--url` | Mattermost server host (no scheme) | — |
|
|
95
|
+
| `--tag` | Trigger tag; messages containing one are forwarded (repeatable) | `@bot` |
|
|
96
|
+
| `--host` | HiveMind hub host (e.g. `ws://127.0.0.1`) | from identity file |
|
|
97
|
+
| `--port` | HiveMind hub port | `5678` |
|
|
98
|
+
| `--key` | HiveMind access key | from identity file |
|
|
99
|
+
| `--password` | HiveMind password | from identity file |
|
|
100
|
+
| `--self-signed` | Accept self-signed SSL certificates | off |
|
|
101
|
+
| `--lang` | Utterance language | `en-us` |
|
|
102
|
+
|
|
103
|
+
## Troubleshooting
|
|
104
|
+
|
|
105
|
+
- **Bot never answers** — confirm the bot account is a member of the channel and the message contains a trigger tag; confirm the hub is reachable and the access key is registered (`hivemind-core list-clients`).
|
|
106
|
+
- **Mattermost login fails** — check `url` is the bare host (no `https://`) and the bot login/password are correct.
|
|
107
|
+
- **No reply posted** — replies are routed by channel and user context; the hub must echo those context keys and produce a `speak` for the answer to land.
|
|
108
|
+
|
|
109
|
+
## Documentation
|
|
110
|
+
|
|
111
|
+
- **[Operator setup](docs/operator-setup.md)** — getting the bot's Mattermost account (or self-hosting `mattermost-preview`), registering the bridge on a HiveMind hub, the run command, and live e2e.
|
|
112
|
+
|
|
113
|
+
See also [`docs/`](docs/) for a full setup walkthrough, a configuration reference, and worked examples.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
pyproject.toml
|
|
3
|
+
readme.md
|
|
4
|
+
requirements.txt
|
|
5
|
+
HiveMind_mattermost_bridge.egg-info/PKG-INFO
|
|
6
|
+
HiveMind_mattermost_bridge.egg-info/SOURCES.txt
|
|
7
|
+
HiveMind_mattermost_bridge.egg-info/dependency_links.txt
|
|
8
|
+
HiveMind_mattermost_bridge.egg-info/entry_points.txt
|
|
9
|
+
HiveMind_mattermost_bridge.egg-info/requires.txt
|
|
10
|
+
HiveMind_mattermost_bridge.egg-info/top_level.txt
|
|
11
|
+
mattermost_bridge/__init__.py
|
|
12
|
+
mattermost_bridge/__main__.py
|
|
13
|
+
mattermost_bridge/mmost.py
|
|
14
|
+
mattermost_bridge/version.py
|
|
15
|
+
tests/test_smoke.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mattermost_bridge
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: HiveMind-mattermost-bridge
|
|
3
|
+
Version: 0.2.0a3
|
|
4
|
+
Summary: Bridge a Mattermost bot account to a HiveMind node
|
|
5
|
+
Author-email: jarbasAI <jarbasai@mailfence.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/JarbasHiveMind/HiveMind_mattermost_bridge
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: hivemind-bus-client<1.0.0,>=0.9.0
|
|
12
|
+
Requires-Dist: mattermostdriver
|
|
13
|
+
Requires-Dist: ovos-utils
|
|
14
|
+
Requires-Dist: ovos-bus-client>=2.0.0a3
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: pytest; extra == "test"
|
|
17
|
+
Provides-Extra: e2e
|
|
18
|
+
Requires-Dist: pytest; extra == "e2e"
|
|
19
|
+
Requires-Dist: hivescope>=0.5.2a1; extra == "e2e"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# HiveMind Mattermost Bridge
|
|
23
|
+
|
|
24
|
+
Relay a [Mattermost](https://mattermost.com) bot account to a [HiveMind](https://github.com/JarbasHiveMind/HiveMind-core) hub.
|
|
25
|
+
|
|
26
|
+
The bridge is a HiveMind **satellite** whose input and output are Mattermost chat instead of a microphone. Mentions and direct messages to the bot become utterances sent to the hub; the hub's spoken reply is posted back to the originating channel. Any HiveMind hub (and the OVOS skills behind it) becomes reachable as a Mattermost chatbot.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
Mattermost channel ⇄ HiveMind_mattermost_bridge ⇄ HiveMind hub ⇄ OVOS skills
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
## Prerequisites
|
|
36
|
+
|
|
37
|
+
- A running **HiveMind hub** ([hivemind-core](https://github.com/JarbasHiveMind/HiveMind-core)) reachable over the network, and a **HiveMind access key** for this bridge (`hivemind-core add-client`).
|
|
38
|
+
- A **Mattermost server** and a **bot user account** on it (an email/login and password the bridge logs in with). The bot must be a member of the channels it should answer in.
|
|
39
|
+
- Python 3.10+.
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
git clone https://github.com/JarbasHiveMind/HiveMind_mattermost_bridge
|
|
45
|
+
cd HiveMind_mattermost_bridge
|
|
46
|
+
pip install .
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This installs the `hivemind-mattermost-bridge` console script.
|
|
50
|
+
|
|
51
|
+
Dependencies: `hivemind-bus-client`, `mattermostdriver`, `ovos-utils`, `ovos-bus-client`.
|
|
52
|
+
|
|
53
|
+
## Quickstart
|
|
54
|
+
|
|
55
|
+
**1. Register the bridge on the hub** (where `hivemind-core` is installed):
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
hivemind-core add-client --name mattermost-bridge \
|
|
59
|
+
--access-key "your-access-key" --password "your-password"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**2. Run the bridge.** Pass Mattermost credentials and HiveMind identity as flags (HiveMind key/password/host default to the values stored by `hivemind-client set-identity`):
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
hivemind-mattermost-bridge \
|
|
66
|
+
--mail bot@example.com \
|
|
67
|
+
--pswd bot-password \
|
|
68
|
+
--url chat.example.com \
|
|
69
|
+
--tag @bot \
|
|
70
|
+
--host ws://127.0.0.1 \
|
|
71
|
+
--port 5678 \
|
|
72
|
+
--key your-access-key \
|
|
73
|
+
--password your-hivemind-password
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Or run as a module: `python -m mattermost_bridge --help`.
|
|
77
|
+
|
|
78
|
+
**3. Send a message.** In a channel the bot is in, mention it:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
@bot what time is it?
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The bridge forwards the message to the hub and posts the hub's reply back to the channel.
|
|
85
|
+
|
|
86
|
+
## Configuration
|
|
87
|
+
|
|
88
|
+
CLI flags (`hivemind-mattermost-bridge --help`):
|
|
89
|
+
|
|
90
|
+
| Flag | Description | Default |
|
|
91
|
+
| --- | --- | --- |
|
|
92
|
+
| `--mail` | Mattermost bot account login (email) | — |
|
|
93
|
+
| `--pswd` | Mattermost bot account password | — |
|
|
94
|
+
| `--url` | Mattermost server host (no scheme) | — |
|
|
95
|
+
| `--tag` | Trigger tag; messages containing one are forwarded (repeatable) | `@bot` |
|
|
96
|
+
| `--host` | HiveMind hub host (e.g. `ws://127.0.0.1`) | from identity file |
|
|
97
|
+
| `--port` | HiveMind hub port | `5678` |
|
|
98
|
+
| `--key` | HiveMind access key | from identity file |
|
|
99
|
+
| `--password` | HiveMind password | from identity file |
|
|
100
|
+
| `--self-signed` | Accept self-signed SSL certificates | off |
|
|
101
|
+
| `--lang` | Utterance language | `en-us` |
|
|
102
|
+
|
|
103
|
+
## Troubleshooting
|
|
104
|
+
|
|
105
|
+
- **Bot never answers** — confirm the bot account is a member of the channel and the message contains a trigger tag; confirm the hub is reachable and the access key is registered (`hivemind-core list-clients`).
|
|
106
|
+
- **Mattermost login fails** — check `url` is the bare host (no `https://`) and the bot login/password are correct.
|
|
107
|
+
- **No reply posted** — replies are routed by channel and user context; the hub must echo those context keys and produce a `speak` for the answer to land.
|
|
108
|
+
|
|
109
|
+
## Documentation
|
|
110
|
+
|
|
111
|
+
- **[Operator setup](docs/operator-setup.md)** — getting the bot's Mattermost account (or self-hosting `mattermost-preview`), registering the bridge on a HiveMind hub, the run command, and live e2e.
|
|
112
|
+
|
|
113
|
+
See also [`docs/`](docs/) for a full setup walkthrough, a configuration reference, and worked examples.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"""HiveMind <-> Mattermost bridge.
|
|
2
|
+
|
|
3
|
+
Modernized from the legacy ``jarbas_hive_mind`` (pre-rename, Mycroft-era,
|
|
4
|
+
Tornado-based ``HiveMindTerminal``) to the modern ``hivemind-bus-client``
|
|
5
|
+
:class:`~hivemind_bus_client.HiveMessageBusClient`.
|
|
6
|
+
|
|
7
|
+
Composition design (replaces the old ``JarbasMattermostBridge`` that
|
|
8
|
+
*extended* ``HiveMindTerminal``):
|
|
9
|
+
|
|
10
|
+
- :class:`mattermost_bridge.mmost.MMostBot` wraps ``mattermostdriver``.
|
|
11
|
+
``MMostBot.listen()`` is a blocking call driving the driver's own
|
|
12
|
+
websocket loop, so we run it in a daemon thread.
|
|
13
|
+
- :class:`HiveMindMattermostBridge` owns a
|
|
14
|
+
:class:`~hivemind_bus_client.HiveMessageBusClient`, registers a ``speak``
|
|
15
|
+
handler to forward HiveMind replies back to Mattermost, and forwards
|
|
16
|
+
inbound Mattermost messages onto the HiveMind bus as
|
|
17
|
+
``recognizer_loop:utterance``.
|
|
18
|
+
|
|
19
|
+
The HiveMind ``speak`` handler and the Mattermost callbacks run on threads
|
|
20
|
+
owned by their respective libraries; ``MMostBot.send_message`` and
|
|
21
|
+
``HiveMessageBusClient.emit`` are both safe to call from those threads.
|
|
22
|
+
"""
|
|
23
|
+
from typing import List, Optional
|
|
24
|
+
|
|
25
|
+
from hivemind_bus_client import (
|
|
26
|
+
HiveMessage,
|
|
27
|
+
HiveMessageType,
|
|
28
|
+
HiveMessageBusClient,
|
|
29
|
+
)
|
|
30
|
+
from ovos_bus_client.message import Message
|
|
31
|
+
from ovos_utils import create_daemon
|
|
32
|
+
from ovos_utils.log import LOG
|
|
33
|
+
|
|
34
|
+
from mattermost_bridge.mmost import MMostBot
|
|
35
|
+
|
|
36
|
+
platform = "HiveMindMattermostBridgeV0.2"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class HiveMindMattermostBridge:
|
|
40
|
+
"""Bridge Mattermost direct-messages/mentions to a HiveMind node."""
|
|
41
|
+
|
|
42
|
+
def __init__(self,
|
|
43
|
+
mail: Optional[str] = None,
|
|
44
|
+
pswd: Optional[str] = None,
|
|
45
|
+
url: Optional[str] = None,
|
|
46
|
+
tags: Optional[List[str]] = None,
|
|
47
|
+
key: Optional[str] = None,
|
|
48
|
+
password: Optional[str] = None,
|
|
49
|
+
host: Optional[str] = None,
|
|
50
|
+
port: int = 5678,
|
|
51
|
+
self_signed: bool = False,
|
|
52
|
+
lang: str = "en-us",
|
|
53
|
+
*,
|
|
54
|
+
client: Optional[HiveMessageBusClient] = None,
|
|
55
|
+
bot: Optional[MMostBot] = None):
|
|
56
|
+
self.lang = lang
|
|
57
|
+
self.bot = bot or MMostBot(mail, pswd, url, tags=tags)
|
|
58
|
+
self.bot.handle_mention = self.handle_mmost_message
|
|
59
|
+
self.bot.handle_direct_message = self.handle_mmost_message
|
|
60
|
+
|
|
61
|
+
# NOTE: HiveMessageBusClient does NOT open a connection in __init__;
|
|
62
|
+
# call connect() (see start()). This keeps the object constructible
|
|
63
|
+
# offline for tests.
|
|
64
|
+
self.client = client or HiveMessageBusClient(
|
|
65
|
+
key=key,
|
|
66
|
+
password=password,
|
|
67
|
+
host=host,
|
|
68
|
+
port=port,
|
|
69
|
+
useragent=platform,
|
|
70
|
+
self_signed=self_signed,
|
|
71
|
+
)
|
|
72
|
+
self._started = False
|
|
73
|
+
|
|
74
|
+
# ------------------------------------------------------------------
|
|
75
|
+
# lifecycle
|
|
76
|
+
# ------------------------------------------------------------------
|
|
77
|
+
|
|
78
|
+
def start(self) -> None:
|
|
79
|
+
"""Connect to HiveMind and start listening to Mattermost."""
|
|
80
|
+
if self._started:
|
|
81
|
+
return
|
|
82
|
+
self.client.connect(site_id="mattermost")
|
|
83
|
+
self.client.on_mycroft("speak", self.handle_speak)
|
|
84
|
+
self.client.on_mycroft("hive.complete_intent_failure",
|
|
85
|
+
self.handle_intent_failure)
|
|
86
|
+
LOG.info("== connected to HiveMind")
|
|
87
|
+
# MMostBot.listen() blocks on the driver websocket loop -> daemon it
|
|
88
|
+
create_daemon(self.bot.listen)
|
|
89
|
+
LOG.info("== listening to Mattermost")
|
|
90
|
+
self._started = True
|
|
91
|
+
|
|
92
|
+
def stop(self) -> None:
|
|
93
|
+
if not self._started:
|
|
94
|
+
return
|
|
95
|
+
try:
|
|
96
|
+
self.client.close()
|
|
97
|
+
except Exception:
|
|
98
|
+
LOG.exception("error closing HiveMind client")
|
|
99
|
+
self._started = False
|
|
100
|
+
|
|
101
|
+
# ------------------------------------------------------------------
|
|
102
|
+
# Mattermost -> HiveMind
|
|
103
|
+
# ------------------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
def handle_mmost_message(self, message: str, sender: str,
|
|
106
|
+
channel_id: str) -> None:
|
|
107
|
+
"""Forward an inbound Mattermost message onto the HiveMind bus."""
|
|
108
|
+
msg = Message(
|
|
109
|
+
"recognizer_loop:utterance",
|
|
110
|
+
{"utterances": [message], "lang": self.lang},
|
|
111
|
+
{
|
|
112
|
+
"source": platform,
|
|
113
|
+
"destination": "HiveMind",
|
|
114
|
+
"platform": platform,
|
|
115
|
+
"channel": channel_id,
|
|
116
|
+
"user": {"mattermost_username": sender},
|
|
117
|
+
},
|
|
118
|
+
)
|
|
119
|
+
self.client.emit(HiveMessage(HiveMessageType.BUS, msg))
|
|
120
|
+
|
|
121
|
+
# ------------------------------------------------------------------
|
|
122
|
+
# HiveMind -> Mattermost
|
|
123
|
+
# ------------------------------------------------------------------
|
|
124
|
+
|
|
125
|
+
def handle_speak(self, message: Message) -> None:
|
|
126
|
+
channel_id = message.context.get("channel")
|
|
127
|
+
user_data = message.context.get("user")
|
|
128
|
+
if not channel_id or not user_data:
|
|
129
|
+
return
|
|
130
|
+
utterance = message.data.get("utterance")
|
|
131
|
+
if not utterance:
|
|
132
|
+
return
|
|
133
|
+
self.speak(utterance, channel_id, user_data)
|
|
134
|
+
|
|
135
|
+
def handle_intent_failure(self, message: Message) -> None:
|
|
136
|
+
channel_id = message.context.get("channel")
|
|
137
|
+
user_data = message.context.get("user")
|
|
138
|
+
if not channel_id or not user_data:
|
|
139
|
+
return
|
|
140
|
+
LOG.error("complete intent failure")
|
|
141
|
+
self.speak("I don't know how to answer that", channel_id, user_data)
|
|
142
|
+
|
|
143
|
+
def speak(self, utterance: str, channel_id: str, user_data: dict) -> None:
|
|
144
|
+
user = user_data.get("mattermost_username") or "user"
|
|
145
|
+
text = f"@{user} , {utterance}"
|
|
146
|
+
LOG.debug(f"Sending message to channel {channel_id}: {text}")
|
|
147
|
+
try:
|
|
148
|
+
self.bot.send_message(channel_id, text)
|
|
149
|
+
except Exception:
|
|
150
|
+
LOG.exception(
|
|
151
|
+
f"failed to send mattermost message to channel={channel_id}")
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
# Backwards-compat alias for the old public name. The old class extended the
|
|
155
|
+
# Tornado HiveMindTerminal; anyone relying on those internals will get an
|
|
156
|
+
# AttributeError at runtime, which is the honest failure mode.
|
|
157
|
+
JarbasMattermostBridge = HiveMindMattermostBridge
|
|
158
|
+
|
|
159
|
+
__all__ = ["HiveMindMattermostBridge", "JarbasMattermostBridge", "platform"]
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""CLI entry point for the HiveMind <-> Mattermost bridge.
|
|
2
|
+
|
|
3
|
+
HiveMind identity (key/password/host/port) defaults to the values stored by
|
|
4
|
+
``hivemind-client set-identity``; flags override them.
|
|
5
|
+
"""
|
|
6
|
+
import argparse
|
|
7
|
+
|
|
8
|
+
from ovos_utils.log import LOG
|
|
9
|
+
|
|
10
|
+
from mattermost_bridge import HiveMindMattermostBridge
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def connect_mattermost_to_hivemind(mail, pswd, url, tags=None,
|
|
14
|
+
key=None, password=None,
|
|
15
|
+
host=None, port=5678,
|
|
16
|
+
self_signed=False, lang="en-us"):
|
|
17
|
+
bridge = HiveMindMattermostBridge(
|
|
18
|
+
mail=mail, pswd=pswd, url=url, tags=tags or ["@bot"],
|
|
19
|
+
key=key, password=password, host=host, port=port,
|
|
20
|
+
self_signed=self_signed, lang=lang,
|
|
21
|
+
)
|
|
22
|
+
bridge.start()
|
|
23
|
+
return bridge
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def main():
|
|
27
|
+
parser = argparse.ArgumentParser(
|
|
28
|
+
description="Bridge a Mattermost bot account to a HiveMind node")
|
|
29
|
+
# Mattermost
|
|
30
|
+
parser.add_argument("--mail", required=True,
|
|
31
|
+
help="Mattermost bot account email / login id")
|
|
32
|
+
parser.add_argument("--pswd", required=True,
|
|
33
|
+
help="Mattermost bot account password")
|
|
34
|
+
parser.add_argument("--url", required=True,
|
|
35
|
+
help="Mattermost server host (no scheme, e.g. chat.example.com)")
|
|
36
|
+
parser.add_argument("--tag", dest="tags", action="append", default=None,
|
|
37
|
+
help="tag that triggers the bot (repeatable, default: @bot)")
|
|
38
|
+
# HiveMind
|
|
39
|
+
parser.add_argument("--key", default=None,
|
|
40
|
+
help="HiveMind access key (default: from identity file)")
|
|
41
|
+
parser.add_argument("--password", default=None,
|
|
42
|
+
help="HiveMind password (default: from identity file)")
|
|
43
|
+
parser.add_argument("--host", default=None,
|
|
44
|
+
help="HiveMind host, e.g. ws://127.0.0.1 (default: from identity file)")
|
|
45
|
+
parser.add_argument("--port", type=int, default=5678,
|
|
46
|
+
help="HiveMind port (default: 5678)")
|
|
47
|
+
parser.add_argument("--self-signed", action="store_true",
|
|
48
|
+
help="accept self-signed SSL certificates")
|
|
49
|
+
parser.add_argument("--lang", default="en-us", help="utterance language")
|
|
50
|
+
|
|
51
|
+
args = parser.parse_args()
|
|
52
|
+
|
|
53
|
+
host = args.host
|
|
54
|
+
if host and not host.startswith("ws://") and not host.startswith("wss://"):
|
|
55
|
+
host = "ws://" + host
|
|
56
|
+
|
|
57
|
+
connect_mattermost_to_hivemind(
|
|
58
|
+
mail=args.mail, pswd=args.pswd, url=args.url, tags=args.tags,
|
|
59
|
+
key=args.key, password=args.password, host=host, port=args.port,
|
|
60
|
+
self_signed=args.self_signed, lang=args.lang,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
LOG.info("bridge running; press Ctrl-C to stop")
|
|
64
|
+
try:
|
|
65
|
+
import time
|
|
66
|
+
while True:
|
|
67
|
+
time.sleep(1)
|
|
68
|
+
except KeyboardInterrupt:
|
|
69
|
+
LOG.info("shutting down")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if __name__ == '__main__':
|
|
73
|
+
main()
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
from mattermostdriver import Driver
|
|
2
|
+
from ovos_utils.log import LOG
|
|
3
|
+
import logging
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
logging.getLogger("urllib3.connectionpool").setLevel("WARNING")
|
|
8
|
+
logging.getLogger("asyncio").setLevel("WARNING")
|
|
9
|
+
logging.getLogger("websockets.client").setLevel("WARNING")
|
|
10
|
+
logging.getLogger("websockets.protocol").setLevel("WARNING")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MMostBot:
|
|
14
|
+
def __init__(self, mail, pswd, url, tags=None, debug=False):
|
|
15
|
+
self.debug = debug
|
|
16
|
+
self.config = {"url": url,
|
|
17
|
+
"login_id": mail,
|
|
18
|
+
"password": pswd,
|
|
19
|
+
"scheme": "https",
|
|
20
|
+
"port": 443,
|
|
21
|
+
"verify": True,
|
|
22
|
+
"debug": debug}
|
|
23
|
+
self.driver = Driver(self.config)
|
|
24
|
+
self.tags = tags or []
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def user_id(self):
|
|
28
|
+
return self.driver.users.get_user(user_id='me')["id"]
|
|
29
|
+
|
|
30
|
+
def listen(self):
|
|
31
|
+
self.driver.login()
|
|
32
|
+
self.driver.init_websocket(self.event_handler)
|
|
33
|
+
|
|
34
|
+
async def event_handler(self, event):
|
|
35
|
+
event = json.loads(event)
|
|
36
|
+
event_type = event.get("event", "")
|
|
37
|
+
if event_type == "hello":
|
|
38
|
+
self.on_connect(event)
|
|
39
|
+
elif event_type == "status_change":
|
|
40
|
+
self.on_status_change(event)
|
|
41
|
+
elif event_type == "typing":
|
|
42
|
+
self.on_typing(event)
|
|
43
|
+
elif event_type == "posted":
|
|
44
|
+
self.on_message(event)
|
|
45
|
+
elif event_type == "channel_viewed":
|
|
46
|
+
self.on_viewed(event)
|
|
47
|
+
elif event_type == "preferences_changed":
|
|
48
|
+
self.on_preferences_changed(event)
|
|
49
|
+
elif event_type == "post_deleted":
|
|
50
|
+
self.on_post_deleted(event)
|
|
51
|
+
elif event_type == "user_added":
|
|
52
|
+
self.on_user_added(event)
|
|
53
|
+
elif event_type == "user_removed":
|
|
54
|
+
self.on_user_removed(event)
|
|
55
|
+
else:
|
|
56
|
+
LOG.debug(event)
|
|
57
|
+
|
|
58
|
+
def on_connect(self, event):
|
|
59
|
+
LOG.info("Connected")
|
|
60
|
+
|
|
61
|
+
def on_status_change(self, event):
|
|
62
|
+
user_id = event["data"]["user_id"]
|
|
63
|
+
status = event["data"]["status"]
|
|
64
|
+
|
|
65
|
+
user_data = self.driver.users.get_user(user_id=user_id)
|
|
66
|
+
username = user_data["username"]
|
|
67
|
+
email = user_data["email"]
|
|
68
|
+
|
|
69
|
+
LOG.info(username + ":" + status)
|
|
70
|
+
|
|
71
|
+
def on_typing(self, event):
|
|
72
|
+
user_id = event["data"]["user_id"]
|
|
73
|
+
channel_id = event["broadcast"]["channel_id"]
|
|
74
|
+
|
|
75
|
+
channel_data = self.driver.channels.get_channel(channel_id)
|
|
76
|
+
channel_name = channel_data["name"]
|
|
77
|
+
|
|
78
|
+
user_data = self.driver.users.get_user(user_id=user_id)
|
|
79
|
+
username = user_data["username"]
|
|
80
|
+
|
|
81
|
+
if channel_name == self.user_id + "__" + user_id:
|
|
82
|
+
LOG.info(username + " is typing a direct message")
|
|
83
|
+
else:
|
|
84
|
+
LOG.info(username + " is typing a message in channel: " + channel_name)
|
|
85
|
+
|
|
86
|
+
def on_message(self, event):
|
|
87
|
+
post = event["data"]["post"]
|
|
88
|
+
post = json.loads(post)
|
|
89
|
+
sender = event["data"]["sender_name"]
|
|
90
|
+
msg = post["message"]
|
|
91
|
+
channel_id = post["channel_id"]
|
|
92
|
+
user_id = post["user_id"]
|
|
93
|
+
|
|
94
|
+
channel_data = self.driver.channels.get_channel(channel_id)
|
|
95
|
+
channel_name = channel_data["name"]
|
|
96
|
+
|
|
97
|
+
if channel_name == self.user_id + "__" + user_id:
|
|
98
|
+
# direct_message
|
|
99
|
+
if user_id != self.user_id:
|
|
100
|
+
self.on_direct_message(event)
|
|
101
|
+
else:
|
|
102
|
+
if user_id != self.user_id:
|
|
103
|
+
mention = False
|
|
104
|
+
for tag in self.tags:
|
|
105
|
+
if tag in msg:
|
|
106
|
+
mention = True
|
|
107
|
+
break
|
|
108
|
+
if mention:
|
|
109
|
+
self.on_mention(event)
|
|
110
|
+
else:
|
|
111
|
+
LOG.info("New message at channel: " + channel_name)
|
|
112
|
+
LOG.info(sender + " said: " + msg)
|
|
113
|
+
|
|
114
|
+
def on_mention(self, event):
|
|
115
|
+
post = event["data"]["post"]
|
|
116
|
+
post = json.loads(post)
|
|
117
|
+
sender = event["data"]["sender_name"]
|
|
118
|
+
msg = post["message"]
|
|
119
|
+
channel_id = post["channel_id"]
|
|
120
|
+
user_id = post["user_id"]
|
|
121
|
+
channel_data = self.driver.channels.get_channel(channel_id)
|
|
122
|
+
channel_name = channel_data["name"]
|
|
123
|
+
|
|
124
|
+
for tag in self.tags:
|
|
125
|
+
msg = msg.replace(tag, "")
|
|
126
|
+
|
|
127
|
+
LOG.info("New mention at channel: " + channel_name)
|
|
128
|
+
LOG.info(sender + " said: " + msg)
|
|
129
|
+
|
|
130
|
+
self.handle_mention(msg, sender, channel_id)
|
|
131
|
+
|
|
132
|
+
def on_user_added(self, event):
|
|
133
|
+
user_id = event["data"]["user_id"]
|
|
134
|
+
channel_id = event["broadcast"]["channel_id"]
|
|
135
|
+
|
|
136
|
+
if user_id != self.user_id:
|
|
137
|
+
user_data = self.driver.users.get_user(user_id=user_id)
|
|
138
|
+
username = user_data["username"]
|
|
139
|
+
self.send_message(channel_id, "hello @"+username)
|
|
140
|
+
else:
|
|
141
|
+
self.send_message(channel_id, "Blip Blop, I am a Bot!")
|
|
142
|
+
|
|
143
|
+
def on_user_removed(self, event):
|
|
144
|
+
user_id = event["broadcast"]["user_id"]
|
|
145
|
+
#channel_id = event["data"]["channel_id"]
|
|
146
|
+
#remover_id = event["data"]["remover_id"]
|
|
147
|
+
|
|
148
|
+
def on_direct_message(self, event):
|
|
149
|
+
post = event["data"]["post"]
|
|
150
|
+
post = json.loads(post)
|
|
151
|
+
sender = event["data"]["sender_name"]
|
|
152
|
+
msg = post["message"]
|
|
153
|
+
channel_id = post["channel_id"]
|
|
154
|
+
|
|
155
|
+
LOG.info("Direct Message from: " + sender)
|
|
156
|
+
LOG.info("Message: " + msg)
|
|
157
|
+
# echo
|
|
158
|
+
self.handle_direct_message(msg, sender, channel_id)
|
|
159
|
+
|
|
160
|
+
def on_viewed(self, event):
|
|
161
|
+
channel_id = event["data"]["channel_id"]
|
|
162
|
+
user_id = event["broadcast"]["user_id"]
|
|
163
|
+
|
|
164
|
+
def on_preferences_changed(self, event):
|
|
165
|
+
preferences = json.loads(event["data"]["preferences"])
|
|
166
|
+
for pref in preferences:
|
|
167
|
+
user_id = pref["user_id"]
|
|
168
|
+
category = pref["category"]
|
|
169
|
+
value = pref["value"]
|
|
170
|
+
LOG.debug(category + ":" + value)
|
|
171
|
+
|
|
172
|
+
def on_post_deleted(self, event):
|
|
173
|
+
msg = event["data"]["message"]
|
|
174
|
+
|
|
175
|
+
def send_message(self, channel_id, message, file_paths=None):
|
|
176
|
+
file_paths = file_paths or []
|
|
177
|
+
file_ids = []
|
|
178
|
+
# TODO not working
|
|
179
|
+
#for f in file_paths:
|
|
180
|
+
# file_id = self.driver.files.upload_file(
|
|
181
|
+
# channel_id=channel_id,
|
|
182
|
+
# files = {'files': (f, open(f))}
|
|
183
|
+
# )['file_infos'][0]['id']
|
|
184
|
+
# file_ids.append(file_id)
|
|
185
|
+
|
|
186
|
+
post = {
|
|
187
|
+
'channel_id': channel_id,
|
|
188
|
+
'message': message}
|
|
189
|
+
if len(file_ids):
|
|
190
|
+
post["file_ids"] = file_ids
|
|
191
|
+
|
|
192
|
+
self.driver.posts.create_post(options=post)
|
|
193
|
+
|
|
194
|
+
# Relevant handlers
|
|
195
|
+
def handle_direct_message(self, message, sender, channel_id):
|
|
196
|
+
pass
|
|
197
|
+
|
|
198
|
+
def handle_mention(self, message, sender, channel_id):
|
|
199
|
+
pass
|
|
200
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# The following lines are replaced during the release process.
|
|
2
|
+
# START_VERSION_BLOCK
|
|
3
|
+
VERSION_MAJOR = 0
|
|
4
|
+
VERSION_MINOR = 2
|
|
5
|
+
VERSION_BUILD = 0
|
|
6
|
+
VERSION_ALPHA = 3
|
|
7
|
+
# END_VERSION_BLOCK
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
__version__ = (
|
|
11
|
+
f"{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_BUILD}"
|
|
12
|
+
+ (f"a{VERSION_ALPHA}" if VERSION_ALPHA else "")
|
|
13
|
+
)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "HiveMind-mattermost-bridge"
|
|
7
|
+
description = "Bridge a Mattermost bot account to a HiveMind node"
|
|
8
|
+
readme = "readme.md"
|
|
9
|
+
authors = [{ name = "jarbasAI", email = "jarbasai@mailfence.com" }]
|
|
10
|
+
license = { text = "Apache-2.0" }
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dynamic = ["version", "dependencies"]
|
|
13
|
+
|
|
14
|
+
[project.optional-dependencies]
|
|
15
|
+
test = ["pytest"]
|
|
16
|
+
# REAL HiveMind-side end-to-end deps (tests/e2e). hivescope boots a real
|
|
17
|
+
# hivemind-core loopback hub the bridge drives over a real HiveMessageBusClient.
|
|
18
|
+
# hivescope>=0.5.2a1 carries the loopback + ACL fixes and floors the bus-client
|
|
19
|
+
# 2.x stack (PEP 440 prerelease floor), so it resolves from PyPI with no --pre
|
|
20
|
+
# and the e2e suite runs under the shared build-tests workflow.
|
|
21
|
+
e2e = [
|
|
22
|
+
"pytest",
|
|
23
|
+
"hivescope>=0.5.2a1",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/JarbasHiveMind/HiveMind_mattermost_bridge"
|
|
28
|
+
|
|
29
|
+
[project.scripts]
|
|
30
|
+
hivemind-mattermost-bridge = "mattermost_bridge.__main__:main"
|
|
31
|
+
|
|
32
|
+
[tool.setuptools]
|
|
33
|
+
packages = ["mattermost_bridge"]
|
|
34
|
+
include-package-data = true
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.dynamic]
|
|
37
|
+
version = { attr = "mattermost_bridge.version.__version__" }
|
|
38
|
+
dependencies = { file = ["requirements.txt"] }
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# HiveMind Mattermost Bridge
|
|
2
|
+
|
|
3
|
+
Relay a [Mattermost](https://mattermost.com) bot account to a [HiveMind](https://github.com/JarbasHiveMind/HiveMind-core) hub.
|
|
4
|
+
|
|
5
|
+
The bridge is a HiveMind **satellite** whose input and output are Mattermost chat instead of a microphone. Mentions and direct messages to the bot become utterances sent to the hub; the hub's spoken reply is posted back to the originating channel. Any HiveMind hub (and the OVOS skills behind it) becomes reachable as a Mattermost chatbot.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Mattermost channel ⇄ HiveMind_mattermost_bridge ⇄ HiveMind hub ⇄ OVOS skills
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
## Prerequisites
|
|
15
|
+
|
|
16
|
+
- A running **HiveMind hub** ([hivemind-core](https://github.com/JarbasHiveMind/HiveMind-core)) reachable over the network, and a **HiveMind access key** for this bridge (`hivemind-core add-client`).
|
|
17
|
+
- A **Mattermost server** and a **bot user account** on it (an email/login and password the bridge logs in with). The bot must be a member of the channels it should answer in.
|
|
18
|
+
- Python 3.10+.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
git clone https://github.com/JarbasHiveMind/HiveMind_mattermost_bridge
|
|
24
|
+
cd HiveMind_mattermost_bridge
|
|
25
|
+
pip install .
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
This installs the `hivemind-mattermost-bridge` console script.
|
|
29
|
+
|
|
30
|
+
Dependencies: `hivemind-bus-client`, `mattermostdriver`, `ovos-utils`, `ovos-bus-client`.
|
|
31
|
+
|
|
32
|
+
## Quickstart
|
|
33
|
+
|
|
34
|
+
**1. Register the bridge on the hub** (where `hivemind-core` is installed):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
hivemind-core add-client --name mattermost-bridge \
|
|
38
|
+
--access-key "your-access-key" --password "your-password"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**2. Run the bridge.** Pass Mattermost credentials and HiveMind identity as flags (HiveMind key/password/host default to the values stored by `hivemind-client set-identity`):
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
hivemind-mattermost-bridge \
|
|
45
|
+
--mail bot@example.com \
|
|
46
|
+
--pswd bot-password \
|
|
47
|
+
--url chat.example.com \
|
|
48
|
+
--tag @bot \
|
|
49
|
+
--host ws://127.0.0.1 \
|
|
50
|
+
--port 5678 \
|
|
51
|
+
--key your-access-key \
|
|
52
|
+
--password your-hivemind-password
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or run as a module: `python -m mattermost_bridge --help`.
|
|
56
|
+
|
|
57
|
+
**3. Send a message.** In a channel the bot is in, mention it:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
@bot what time is it?
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The bridge forwards the message to the hub and posts the hub's reply back to the channel.
|
|
64
|
+
|
|
65
|
+
## Configuration
|
|
66
|
+
|
|
67
|
+
CLI flags (`hivemind-mattermost-bridge --help`):
|
|
68
|
+
|
|
69
|
+
| Flag | Description | Default |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| `--mail` | Mattermost bot account login (email) | — |
|
|
72
|
+
| `--pswd` | Mattermost bot account password | — |
|
|
73
|
+
| `--url` | Mattermost server host (no scheme) | — |
|
|
74
|
+
| `--tag` | Trigger tag; messages containing one are forwarded (repeatable) | `@bot` |
|
|
75
|
+
| `--host` | HiveMind hub host (e.g. `ws://127.0.0.1`) | from identity file |
|
|
76
|
+
| `--port` | HiveMind hub port | `5678` |
|
|
77
|
+
| `--key` | HiveMind access key | from identity file |
|
|
78
|
+
| `--password` | HiveMind password | from identity file |
|
|
79
|
+
| `--self-signed` | Accept self-signed SSL certificates | off |
|
|
80
|
+
| `--lang` | Utterance language | `en-us` |
|
|
81
|
+
|
|
82
|
+
## Troubleshooting
|
|
83
|
+
|
|
84
|
+
- **Bot never answers** — confirm the bot account is a member of the channel and the message contains a trigger tag; confirm the hub is reachable and the access key is registered (`hivemind-core list-clients`).
|
|
85
|
+
- **Mattermost login fails** — check `url` is the bare host (no `https://`) and the bot login/password are correct.
|
|
86
|
+
- **No reply posted** — replies are routed by channel and user context; the hub must echo those context keys and produce a `speak` for the answer to land.
|
|
87
|
+
|
|
88
|
+
## Documentation
|
|
89
|
+
|
|
90
|
+
- **[Operator setup](docs/operator-setup.md)** — getting the bot's Mattermost account (or self-hosting `mattermost-preview`), registering the bridge on a HiveMind hub, the run command, and live e2e.
|
|
91
|
+
|
|
92
|
+
See also [`docs/`](docs/) for a full setup walkthrough, a configuration reference, and worked examples.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Smoke tests: import the package and construct the bridge offline.
|
|
2
|
+
|
|
3
|
+
No live Mattermost or HiveMind connection is made. The mattermostdriver
|
|
4
|
+
``Driver`` is constructed for real (it does not touch the network until
|
|
5
|
+
``login()``), and a pre-built mock HiveMessageBusClient is injected so the
|
|
6
|
+
bridge's __init__ never tries to build a NodeIdentity.
|
|
7
|
+
"""
|
|
8
|
+
from unittest.mock import MagicMock
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_import_package_and_version():
|
|
12
|
+
import mattermost_bridge
|
|
13
|
+
from mattermost_bridge.version import __version__
|
|
14
|
+
|
|
15
|
+
assert isinstance(__version__, str)
|
|
16
|
+
assert __version__
|
|
17
|
+
assert mattermost_bridge.platform.startswith("HiveMindMattermostBridge")
|
|
18
|
+
# public class + back-compat alias
|
|
19
|
+
assert mattermost_bridge.HiveMindMattermostBridge is \
|
|
20
|
+
mattermost_bridge.JarbasMattermostBridge
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_construct_bridge_without_connecting():
|
|
24
|
+
"""Build the bridge with a fake HiveMind client; never connect."""
|
|
25
|
+
from mattermost_bridge import HiveMindMattermostBridge
|
|
26
|
+
from mattermost_bridge.mmost import MMostBot
|
|
27
|
+
|
|
28
|
+
fake_client = MagicMock(name="HiveMessageBusClient")
|
|
29
|
+
# real MMostBot: Driver() is lazy, no network until listen()/login()
|
|
30
|
+
bot = MMostBot("bot@example.com", "secret", "chat.example.com",
|
|
31
|
+
tags=["@bot"])
|
|
32
|
+
|
|
33
|
+
bridge = HiveMindMattermostBridge(bot=bot, client=fake_client)
|
|
34
|
+
|
|
35
|
+
# bridge wired the bot's handlers to itself
|
|
36
|
+
assert bot.handle_mention == bridge.handle_mmost_message
|
|
37
|
+
assert bot.handle_direct_message == bridge.handle_mmost_message
|
|
38
|
+
assert bridge._started is False
|
|
39
|
+
# no connection attempted on construction
|
|
40
|
+
fake_client.connect.assert_not_called()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_inbound_message_forwarded_to_hivemind():
|
|
44
|
+
"""An inbound Mattermost message becomes a BUS HiveMessage emit."""
|
|
45
|
+
from hivemind_bus_client import HiveMessage, HiveMessageType
|
|
46
|
+
from mattermost_bridge import HiveMindMattermostBridge
|
|
47
|
+
|
|
48
|
+
fake_client = MagicMock(name="HiveMessageBusClient")
|
|
49
|
+
fake_bot = MagicMock(name="MMostBot")
|
|
50
|
+
|
|
51
|
+
bridge = HiveMindMattermostBridge(bot=fake_bot, client=fake_client)
|
|
52
|
+
bridge.handle_mmost_message("hello world", "alice", "chan123")
|
|
53
|
+
|
|
54
|
+
fake_client.emit.assert_called_once()
|
|
55
|
+
sent = fake_client.emit.call_args[0][0]
|
|
56
|
+
assert isinstance(sent, HiveMessage)
|
|
57
|
+
assert sent.msg_type == HiveMessageType.BUS
|
|
58
|
+
payload = sent.payload
|
|
59
|
+
assert payload.msg_type == "recognizer_loop:utterance"
|
|
60
|
+
assert payload.data["utterances"] == ["hello world"]
|
|
61
|
+
assert payload.context["channel"] == "chan123"
|
|
62
|
+
assert payload.context["user"]["mattermost_username"] == "alice"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_speak_routes_back_to_mattermost():
|
|
66
|
+
"""A HiveMind speak message is delivered to the right channel/user."""
|
|
67
|
+
from ovos_bus_client.message import Message
|
|
68
|
+
from mattermost_bridge import HiveMindMattermostBridge
|
|
69
|
+
|
|
70
|
+
fake_client = MagicMock(name="HiveMessageBusClient")
|
|
71
|
+
fake_bot = MagicMock(name="MMostBot")
|
|
72
|
+
|
|
73
|
+
bridge = HiveMindMattermostBridge(bot=fake_bot, client=fake_client)
|
|
74
|
+
msg = Message("speak", {"utterance": "hi there"},
|
|
75
|
+
{"channel": "chan123",
|
|
76
|
+
"user": {"mattermost_username": "alice"}})
|
|
77
|
+
bridge.handle_speak(msg)
|
|
78
|
+
|
|
79
|
+
fake_bot.send_message.assert_called_once()
|
|
80
|
+
channel_id, text = fake_bot.send_message.call_args[0]
|
|
81
|
+
assert channel_id == "chan123"
|
|
82
|
+
assert "@alice" in text
|
|
83
|
+
assert "hi there" in text
|