HiveMind-HackChatBridge 0.1.0a2__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_hackchatbridge-0.1.0a2/HiveMind_HackChatBridge.egg-info/PKG-INFO +114 -0
- hivemind_hackchatbridge-0.1.0a2/HiveMind_HackChatBridge.egg-info/SOURCES.txt +15 -0
- hivemind_hackchatbridge-0.1.0a2/HiveMind_HackChatBridge.egg-info/dependency_links.txt +1 -0
- hivemind_hackchatbridge-0.1.0a2/HiveMind_HackChatBridge.egg-info/entry_points.txt +2 -0
- hivemind_hackchatbridge-0.1.0a2/HiveMind_HackChatBridge.egg-info/requires.txt +14 -0
- hivemind_hackchatbridge-0.1.0a2/HiveMind_HackChatBridge.egg-info/top_level.txt +1 -0
- hivemind_hackchatbridge-0.1.0a2/LICENSE +203 -0
- hivemind_hackchatbridge-0.1.0a2/PKG-INFO +114 -0
- hivemind_hackchatbridge-0.1.0a2/hackchat_bridge/__init__.py +123 -0
- hivemind_hackchatbridge-0.1.0a2/hackchat_bridge/__main__.py +48 -0
- hivemind_hackchatbridge-0.1.0a2/hackchat_bridge/hackchat.py +75 -0
- hivemind_hackchatbridge-0.1.0a2/hackchat_bridge/version.py +13 -0
- hivemind_hackchatbridge-0.1.0a2/pyproject.toml +41 -0
- hivemind_hackchatbridge-0.1.0a2/readme.md +90 -0
- hivemind_hackchatbridge-0.1.0a2/requirements.txt +5 -0
- hivemind_hackchatbridge-0.1.0a2/setup.cfg +4 -0
- hivemind_hackchatbridge-0.1.0a2/tests/test_smoke.py +88 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: HiveMind-HackChatBridge
|
|
3
|
+
Version: 0.1.0a2
|
|
4
|
+
Summary: Relay a hack.chat channel to a HiveMind hub — a HiveMind satellite whose input and output are a hack.chat channel
|
|
5
|
+
Author-email: jarbasAI <jarbasai@mailfence.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/JarbasHiveMind/HiveMind-HackChatBridge
|
|
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: ovos-utils
|
|
13
|
+
Requires-Dist: ovos-bus-client
|
|
14
|
+
Requires-Dist: websocket-client
|
|
15
|
+
Requires-Dist: click
|
|
16
|
+
Provides-Extra: test
|
|
17
|
+
Requires-Dist: pytest; extra == "test"
|
|
18
|
+
Provides-Extra: e2e
|
|
19
|
+
Requires-Dist: pytest; extra == "e2e"
|
|
20
|
+
Requires-Dist: pytest-timeout; extra == "e2e"
|
|
21
|
+
Requires-Dist: hivescope>=0.5.0a2; extra == "e2e"
|
|
22
|
+
Requires-Dist: websockets>=11; extra == "e2e"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# HiveMind HackChat Bridge
|
|
26
|
+
|
|
27
|
+
Relay a [hack.chat](https://hack.chat) channel to a [HiveMind](https://github.com/JarbasHiveMind/HiveMind-core) hub.
|
|
28
|
+
|
|
29
|
+
[hack.chat](https://hack.chat) is a minimal, anonymous, channel-based websocket chat. This bridge is a HiveMind **satellite** whose input and output are a hack.chat channel instead of a microphone. Channel messages become utterances sent to the hub; the hub's spoken reply is posted back into the channel, addressed to the user. Any HiveMind hub (and the OVOS skills behind it) becomes a hack.chat bot.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
hack.chat channel ⇄ HiveMind-HackChatBridge ⇄ HiveMind hub ⇄ OVOS skills
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+

|
|
36
|
+

|
|
37
|
+
|
|
38
|
+
## Prerequisites
|
|
39
|
+
|
|
40
|
+
- 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`).
|
|
41
|
+
- A **hack.chat channel name** to join, and a **nickname** for the bot. hack.chat is anonymous — no account or token is required.
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install HiveMind-HackChatBridge
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or from a checkout:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
git clone https://github.com/JarbasHiveMind/HiveMind-HackChatBridge
|
|
53
|
+
cd HiveMind-HackChatBridge
|
|
54
|
+
pip install .
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Declared dependencies: `hivemind-bus-client`, `ovos-bus-client`, `ovos-utils`, `websocket-client`, `click`.
|
|
58
|
+
|
|
59
|
+
## Quickstart
|
|
60
|
+
|
|
61
|
+
**1. Register the bridge on the hub** (where `hivemind-core` is installed):
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
hivemind-core add-client --name hackchat-bridge \
|
|
65
|
+
--access-key "your-access-key" --password "your-password"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**2. Run the bridge.** Configuration is passed on the command line via the `hivemind-hackchat-bridge` console script (or `python -m hackchat_bridge`):
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
hivemind-hackchat-bridge \
|
|
72
|
+
--channel your_channel \
|
|
73
|
+
--username Jarbas_BOT \
|
|
74
|
+
--access-key "your-access-key" \
|
|
75
|
+
--password "your-password" \
|
|
76
|
+
--host ws://127.0.0.1 \
|
|
77
|
+
--port 5678
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**4. Send a message.** Open the same channel at `https://hack.chat/?your_channel` and type:
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
what time is it?
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The bridge forwards the message to the hub and posts the reply back as `@user , <answer>`.
|
|
87
|
+
|
|
88
|
+
## Configuration
|
|
89
|
+
|
|
90
|
+
`hivemind-hackchat-bridge` options:
|
|
91
|
+
|
|
92
|
+
| Option | Description | Default |
|
|
93
|
+
| --- | --- | --- |
|
|
94
|
+
| `--channel` | hack.chat channel name to join | — (required) |
|
|
95
|
+
| `--username` | Bot nickname shown in the channel | `Jarbas_BOT` |
|
|
96
|
+
| `--host` | HiveMind hub host (`wss://` / `ws://`) | `ws://127.0.0.1` |
|
|
97
|
+
| `--port` | HiveMind hub port | `5678` |
|
|
98
|
+
| `--access-key` | HiveMind access key | `None` |
|
|
99
|
+
| `--password` | HiveMind password | `None` |
|
|
100
|
+
| `--self-signed` | Accept self-signed SSL certificates | off |
|
|
101
|
+
| `--lang` | Language code for utterances | `en-us` |
|
|
102
|
+
|
|
103
|
+
The bridge forwards every channel message except its own, stripping a leading `@username` mention of the bot before sending.
|
|
104
|
+
|
|
105
|
+
## Troubleshooting
|
|
106
|
+
|
|
107
|
+
- **Bot joins but never answers** — confirm the hub is reachable and the access key/password are registered (`hivemind-core list-clients`), and that the hub produces a `speak` for the answer.
|
|
108
|
+
- **Wrong channel** — the bot and the user must be on the same hack.chat channel name; open `https://hack.chat/?<channel>`.
|
|
109
|
+
|
|
110
|
+
## Documentation
|
|
111
|
+
|
|
112
|
+
- **[Operator setup](docs/operator-setup.md)** — hack.chat is anonymous (no account/token); registering the bridge on a HiveMind hub, the run command, and the network-only live e2e.
|
|
113
|
+
|
|
114
|
+
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_HackChatBridge.egg-info/PKG-INFO
|
|
6
|
+
HiveMind_HackChatBridge.egg-info/SOURCES.txt
|
|
7
|
+
HiveMind_HackChatBridge.egg-info/dependency_links.txt
|
|
8
|
+
HiveMind_HackChatBridge.egg-info/entry_points.txt
|
|
9
|
+
HiveMind_HackChatBridge.egg-info/requires.txt
|
|
10
|
+
HiveMind_HackChatBridge.egg-info/top_level.txt
|
|
11
|
+
hackchat_bridge/__init__.py
|
|
12
|
+
hackchat_bridge/__main__.py
|
|
13
|
+
hackchat_bridge/hackchat.py
|
|
14
|
+
hackchat_bridge/version.py
|
|
15
|
+
tests/test_smoke.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hackchat_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,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: HiveMind-HackChatBridge
|
|
3
|
+
Version: 0.1.0a2
|
|
4
|
+
Summary: Relay a hack.chat channel to a HiveMind hub — a HiveMind satellite whose input and output are a hack.chat channel
|
|
5
|
+
Author-email: jarbasAI <jarbasai@mailfence.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/JarbasHiveMind/HiveMind-HackChatBridge
|
|
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: ovos-utils
|
|
13
|
+
Requires-Dist: ovos-bus-client
|
|
14
|
+
Requires-Dist: websocket-client
|
|
15
|
+
Requires-Dist: click
|
|
16
|
+
Provides-Extra: test
|
|
17
|
+
Requires-Dist: pytest; extra == "test"
|
|
18
|
+
Provides-Extra: e2e
|
|
19
|
+
Requires-Dist: pytest; extra == "e2e"
|
|
20
|
+
Requires-Dist: pytest-timeout; extra == "e2e"
|
|
21
|
+
Requires-Dist: hivescope>=0.5.0a2; extra == "e2e"
|
|
22
|
+
Requires-Dist: websockets>=11; extra == "e2e"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# HiveMind HackChat Bridge
|
|
26
|
+
|
|
27
|
+
Relay a [hack.chat](https://hack.chat) channel to a [HiveMind](https://github.com/JarbasHiveMind/HiveMind-core) hub.
|
|
28
|
+
|
|
29
|
+
[hack.chat](https://hack.chat) is a minimal, anonymous, channel-based websocket chat. This bridge is a HiveMind **satellite** whose input and output are a hack.chat channel instead of a microphone. Channel messages become utterances sent to the hub; the hub's spoken reply is posted back into the channel, addressed to the user. Any HiveMind hub (and the OVOS skills behind it) becomes a hack.chat bot.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
hack.chat channel ⇄ HiveMind-HackChatBridge ⇄ HiveMind hub ⇄ OVOS skills
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+

|
|
36
|
+

|
|
37
|
+
|
|
38
|
+
## Prerequisites
|
|
39
|
+
|
|
40
|
+
- 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`).
|
|
41
|
+
- A **hack.chat channel name** to join, and a **nickname** for the bot. hack.chat is anonymous — no account or token is required.
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install HiveMind-HackChatBridge
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or from a checkout:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
git clone https://github.com/JarbasHiveMind/HiveMind-HackChatBridge
|
|
53
|
+
cd HiveMind-HackChatBridge
|
|
54
|
+
pip install .
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Declared dependencies: `hivemind-bus-client`, `ovos-bus-client`, `ovos-utils`, `websocket-client`, `click`.
|
|
58
|
+
|
|
59
|
+
## Quickstart
|
|
60
|
+
|
|
61
|
+
**1. Register the bridge on the hub** (where `hivemind-core` is installed):
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
hivemind-core add-client --name hackchat-bridge \
|
|
65
|
+
--access-key "your-access-key" --password "your-password"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**2. Run the bridge.** Configuration is passed on the command line via the `hivemind-hackchat-bridge` console script (or `python -m hackchat_bridge`):
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
hivemind-hackchat-bridge \
|
|
72
|
+
--channel your_channel \
|
|
73
|
+
--username Jarbas_BOT \
|
|
74
|
+
--access-key "your-access-key" \
|
|
75
|
+
--password "your-password" \
|
|
76
|
+
--host ws://127.0.0.1 \
|
|
77
|
+
--port 5678
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**4. Send a message.** Open the same channel at `https://hack.chat/?your_channel` and type:
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
what time is it?
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The bridge forwards the message to the hub and posts the reply back as `@user , <answer>`.
|
|
87
|
+
|
|
88
|
+
## Configuration
|
|
89
|
+
|
|
90
|
+
`hivemind-hackchat-bridge` options:
|
|
91
|
+
|
|
92
|
+
| Option | Description | Default |
|
|
93
|
+
| --- | --- | --- |
|
|
94
|
+
| `--channel` | hack.chat channel name to join | — (required) |
|
|
95
|
+
| `--username` | Bot nickname shown in the channel | `Jarbas_BOT` |
|
|
96
|
+
| `--host` | HiveMind hub host (`wss://` / `ws://`) | `ws://127.0.0.1` |
|
|
97
|
+
| `--port` | HiveMind hub port | `5678` |
|
|
98
|
+
| `--access-key` | HiveMind access key | `None` |
|
|
99
|
+
| `--password` | HiveMind password | `None` |
|
|
100
|
+
| `--self-signed` | Accept self-signed SSL certificates | off |
|
|
101
|
+
| `--lang` | Language code for utterances | `en-us` |
|
|
102
|
+
|
|
103
|
+
The bridge forwards every channel message except its own, stripping a leading `@username` mention of the bot before sending.
|
|
104
|
+
|
|
105
|
+
## Troubleshooting
|
|
106
|
+
|
|
107
|
+
- **Bot joins but never answers** — confirm the hub is reachable and the access key/password are registered (`hivemind-core list-clients`), and that the hub produces a `speak` for the answer.
|
|
108
|
+
- **Wrong channel** — the bot and the user must be on the same hack.chat channel name; open `https://hack.chat/?<channel>`.
|
|
109
|
+
|
|
110
|
+
## Documentation
|
|
111
|
+
|
|
112
|
+
- **[Operator setup](docs/operator-setup.md)** — hack.chat is anonymous (no account/token); registering the bridge on a HiveMind hub, the run command, and the network-only live e2e.
|
|
113
|
+
|
|
114
|
+
See also [`docs/`](docs/) for a full setup walkthrough, a configuration reference, and worked examples.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
from ovos_utils import create_daemon
|
|
2
|
+
from ovos_utils.log import LOG
|
|
3
|
+
|
|
4
|
+
from hivemind_bus_client import HiveMessageBusClient
|
|
5
|
+
from ovos_bus_client import Message
|
|
6
|
+
|
|
7
|
+
from hackchat_bridge.hackchat import HackChat
|
|
8
|
+
from hackchat_bridge.version import __version__
|
|
9
|
+
|
|
10
|
+
platform = f"JarbasHackChatBridgeV{__version__}"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class JarbasHackChatBridge:
|
|
14
|
+
"""Relay a hack.chat channel to a HiveMind hub.
|
|
15
|
+
|
|
16
|
+
Channel messages become ``recognizer_loop:utterance`` messages on the
|
|
17
|
+
HiveMind bus; the hub's ``speak`` reply is posted back into the channel,
|
|
18
|
+
addressed to the originating user.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(self, username, channel,
|
|
22
|
+
access_key=None,
|
|
23
|
+
host="ws://127.0.0.1",
|
|
24
|
+
port=5678,
|
|
25
|
+
password=None,
|
|
26
|
+
self_signed=False,
|
|
27
|
+
lang="en-us",
|
|
28
|
+
bus=None):
|
|
29
|
+
self.status = "disconnected"
|
|
30
|
+
self.username = username
|
|
31
|
+
self.channel = channel
|
|
32
|
+
self.lang = lang
|
|
33
|
+
self.hackchat = None
|
|
34
|
+
|
|
35
|
+
if bus:
|
|
36
|
+
# got a connection already
|
|
37
|
+
self.bus = bus
|
|
38
|
+
else:
|
|
39
|
+
# connect to hivemind
|
|
40
|
+
self.bus = HiveMessageBusClient(access_key,
|
|
41
|
+
host=host,
|
|
42
|
+
port=port,
|
|
43
|
+
password=password,
|
|
44
|
+
self_signed=self_signed)
|
|
45
|
+
self.bus.connect()
|
|
46
|
+
|
|
47
|
+
self.bus.on_mycroft("speak", self.handle_speak)
|
|
48
|
+
self.bus.on_mycroft("hive.complete_intent_failure",
|
|
49
|
+
self.handle_intent_failure)
|
|
50
|
+
|
|
51
|
+
def connect_hackchat(self):
|
|
52
|
+
"""Join the hack.chat channel and start relaying messages."""
|
|
53
|
+
self.hackchat = HackChat(self.username, self.channel)
|
|
54
|
+
self.hackchat.on_message += [self.on_hack_message]
|
|
55
|
+
self.hackchat.on_join += [self.on_hack_join]
|
|
56
|
+
self.hackchat.on_open += [self.on_hack_open]
|
|
57
|
+
self.hackchat.on_leave += [self.on_hack_leave]
|
|
58
|
+
self.status = "connected"
|
|
59
|
+
LOG.info("Channel: {0}".format(self.channel))
|
|
60
|
+
LOG.info("Username: {0}".format(self.username))
|
|
61
|
+
create_daemon(self.hackchat.run)
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def online_users(self):
|
|
65
|
+
if self.hackchat is None:
|
|
66
|
+
return []
|
|
67
|
+
return self.hackchat.online_users
|
|
68
|
+
|
|
69
|
+
# hack.chat callbacks
|
|
70
|
+
def on_hack_open(self, connector, users):
|
|
71
|
+
if len(users) == 1:
|
|
72
|
+
self.hackchat.send_message("This channel belongs to me")
|
|
73
|
+
else:
|
|
74
|
+
self.hackchat.send_message("I see {} online users"
|
|
75
|
+
.format(len(users) - 1))
|
|
76
|
+
|
|
77
|
+
def on_hack_join(self, connector, user):
|
|
78
|
+
self.hackchat.send_message("Hello @{}".format(user))
|
|
79
|
+
|
|
80
|
+
def on_hack_leave(self, connector, user):
|
|
81
|
+
self.hackchat.send_message("@{} vanished from cyberspace".format(user))
|
|
82
|
+
|
|
83
|
+
def on_hack_message(self, connector, message, user):
|
|
84
|
+
utterance = message.lower().strip()
|
|
85
|
+
if user != self.username:
|
|
86
|
+
utterance = utterance.replace("@" + self.username.lower(), "").strip()
|
|
87
|
+
self.send_to_hivemind(utterance, user)
|
|
88
|
+
|
|
89
|
+
# hivemind side
|
|
90
|
+
def send_to_hivemind(self, utterance, user):
|
|
91
|
+
"""Forward a channel utterance to the HiveMind hub."""
|
|
92
|
+
msg = Message("recognizer_loop:utterance",
|
|
93
|
+
{"utterances": [utterance], "lang": self.lang},
|
|
94
|
+
{"destination": "hive_mind",
|
|
95
|
+
"platform": platform,
|
|
96
|
+
"user": {"hackchat_username": user}})
|
|
97
|
+
self.bus.emit(msg)
|
|
98
|
+
|
|
99
|
+
def speak(self, utterance, user_data):
|
|
100
|
+
user = user_data["hackchat_username"]
|
|
101
|
+
utterance = "@{} , ".format(user) + utterance
|
|
102
|
+
LOG.debug("Message: " + utterance)
|
|
103
|
+
if self.hackchat is not None:
|
|
104
|
+
self.hackchat.send_message(utterance)
|
|
105
|
+
|
|
106
|
+
def handle_speak(self, message):
|
|
107
|
+
assert isinstance(message, Message)
|
|
108
|
+
user_data = message.context.get("user")
|
|
109
|
+
if user_data:
|
|
110
|
+
utterance = message.data["utterance"]
|
|
111
|
+
self.speak(utterance, user_data)
|
|
112
|
+
|
|
113
|
+
def handle_intent_failure(self, message):
|
|
114
|
+
assert isinstance(message, Message)
|
|
115
|
+
user_data = message.context.get("user")
|
|
116
|
+
if user_data:
|
|
117
|
+
LOG.error("complete intent failure")
|
|
118
|
+
self.speak("I don't know how to answer that", user_data)
|
|
119
|
+
|
|
120
|
+
def run(self):
|
|
121
|
+
"""Connect to hack.chat and block forever."""
|
|
122
|
+
self.connect_hackchat()
|
|
123
|
+
self.bus.run_forever()
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
from hackchat_bridge import JarbasHackChatBridge
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def connect_hackchat_to_hivemind(channel,
|
|
7
|
+
username="Jarbas_BOT",
|
|
8
|
+
access_key=None,
|
|
9
|
+
host="ws://127.0.0.1",
|
|
10
|
+
port=5678,
|
|
11
|
+
password=None,
|
|
12
|
+
self_signed=False,
|
|
13
|
+
lang="en-us"):
|
|
14
|
+
"""Connect a hack.chat channel to a HiveMind hub and block forever."""
|
|
15
|
+
bridge = JarbasHackChatBridge(username=username,
|
|
16
|
+
channel=channel,
|
|
17
|
+
access_key=access_key,
|
|
18
|
+
host=host,
|
|
19
|
+
port=port,
|
|
20
|
+
password=password,
|
|
21
|
+
self_signed=self_signed,
|
|
22
|
+
lang=lang)
|
|
23
|
+
bridge.run()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@click.command()
|
|
27
|
+
@click.option("--channel", required=True, help="hack.chat channel name to join")
|
|
28
|
+
@click.option("--username", default="Jarbas_BOT", help="bot nickname shown in the channel")
|
|
29
|
+
@click.option("--access-key", default=None, help="HiveMind access key")
|
|
30
|
+
@click.option("--password", default=None, help="HiveMind password")
|
|
31
|
+
@click.option("--host", default="ws://127.0.0.1", help="HiveMind hub host (ws:// or wss://)")
|
|
32
|
+
@click.option("--port", default=5678, type=int, help="HiveMind hub port (default 5678)")
|
|
33
|
+
@click.option("--self-signed", is_flag=True, help="accept self signed ssl certificates")
|
|
34
|
+
@click.option("--lang", default="en-us", help="language code for utterances")
|
|
35
|
+
def main(channel, username, access_key, password, host, port, self_signed, lang):
|
|
36
|
+
"""Relay a hack.chat channel to a HiveMind hub."""
|
|
37
|
+
connect_hackchat_to_hivemind(channel=channel,
|
|
38
|
+
username=username,
|
|
39
|
+
access_key=access_key,
|
|
40
|
+
host=host,
|
|
41
|
+
port=port,
|
|
42
|
+
password=password,
|
|
43
|
+
self_signed=self_signed,
|
|
44
|
+
lang=lang)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if __name__ == '__main__':
|
|
48
|
+
main()
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from threading import Thread
|
|
2
|
+
import json
|
|
3
|
+
import websocket
|
|
4
|
+
from time import sleep
|
|
5
|
+
from ovos_utils.log import LOG
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class HackChat:
|
|
9
|
+
"""A library to connect to https://hack.chat.
|
|
10
|
+
<on_message> is <list> of callback functions to receive data from
|
|
11
|
+
https://hack.chat. Add your callback functions to this attribute.
|
|
12
|
+
e.g., on_message += [my_callback]
|
|
13
|
+
The callback function should have 3 parameters, the first for the
|
|
14
|
+
<HackChat> object, the second for the message someone sent and the
|
|
15
|
+
third for the nickname of the sender of the message.
|
|
16
|
+
|
|
17
|
+
https://github.com/gkbrk/hackchat
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, nick, channel="programming", debug=True):
|
|
21
|
+
"""Connects to a channel on https://hack.chat.
|
|
22
|
+
Keyword arguments:
|
|
23
|
+
nick -- <str>; the nickname to use upon joining the channel
|
|
24
|
+
channel -- <str>; the channel to connect to on https://hack.chat
|
|
25
|
+
"""
|
|
26
|
+
self.debug = debug
|
|
27
|
+
self.nick = nick
|
|
28
|
+
self.channel = channel
|
|
29
|
+
self.online_users = []
|
|
30
|
+
self.on_message = []
|
|
31
|
+
self.on_join = []
|
|
32
|
+
self.on_open = []
|
|
33
|
+
self.on_leave = []
|
|
34
|
+
self.ws = websocket.create_connection("wss://hack.chat/chat-ws")
|
|
35
|
+
self._send_packet({"cmd": "join", "channel": channel, "nick": nick})
|
|
36
|
+
Thread(target=self._ping_thread).start()
|
|
37
|
+
|
|
38
|
+
def send_message(self, msg):
|
|
39
|
+
"""Sends a message on the channel."""
|
|
40
|
+
self._send_packet({"cmd": "chat", "text": msg})
|
|
41
|
+
|
|
42
|
+
def _send_packet(self, packet):
|
|
43
|
+
"""Sends <packet> (<dict>) to https://hack.chat."""
|
|
44
|
+
encoded = json.dumps(packet)
|
|
45
|
+
self.ws.send(encoded)
|
|
46
|
+
|
|
47
|
+
def run(self):
|
|
48
|
+
"""Sends data to the callback functions."""
|
|
49
|
+
while True:
|
|
50
|
+
result = json.loads(self.ws.recv())
|
|
51
|
+
if self.debug:
|
|
52
|
+
LOG.debug("[Raw Hackchat] " + str(result))
|
|
53
|
+
|
|
54
|
+
if result["cmd"] == "chat" and not result["nick"] == self.nick:
|
|
55
|
+
for handler in list(self.on_message):
|
|
56
|
+
handler(self, result["text"], result["nick"])
|
|
57
|
+
elif result["cmd"] == "onlineAdd":
|
|
58
|
+
self.online_users.append(result["nick"])
|
|
59
|
+
for handler in list(self.on_join):
|
|
60
|
+
handler(self, result["nick"])
|
|
61
|
+
elif result["cmd"] == "onlineRemove":
|
|
62
|
+
self.online_users.remove(result["nick"])
|
|
63
|
+
for handler in list(self.on_leave):
|
|
64
|
+
handler(self, result["nick"])
|
|
65
|
+
elif result["cmd"] == "onlineSet":
|
|
66
|
+
for nick in result["nicks"]:
|
|
67
|
+
self.online_users.append(nick)
|
|
68
|
+
for handler in list(self.on_open):
|
|
69
|
+
handler(self, result["nicks"])
|
|
70
|
+
|
|
71
|
+
def _ping_thread(self):
|
|
72
|
+
"""Retains the websocket connection."""
|
|
73
|
+
while self.ws.connected:
|
|
74
|
+
self._send_packet({"cmd": "ping"})
|
|
75
|
+
sleep(60)
|
|
@@ -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 = 1
|
|
5
|
+
VERSION_BUILD = 0
|
|
6
|
+
VERSION_ALPHA = 2
|
|
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,41 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "HiveMind-HackChatBridge"
|
|
7
|
+
description = "Relay a hack.chat channel to a HiveMind hub — a HiveMind satellite whose input and output are a hack.chat channel"
|
|
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 end-to-end suite (tests/e2e/). Boots a hivemind-core hub via hivescope
|
|
17
|
+
# and drives the bridge's production HiveMessageBusClient path over a real
|
|
18
|
+
# loopback WebSocket. hivescope must currently come from the
|
|
19
|
+
# fix/loopback-whitelist-only-connection branch (the published build lacks the
|
|
20
|
+
# loopback whitelist-only + get_client_by_id fixes); CI injects that via
|
|
21
|
+
# pre_install_pip, so the constraint here is only a lower bound for local runs.
|
|
22
|
+
e2e = [
|
|
23
|
+
"pytest",
|
|
24
|
+
"pytest-timeout",
|
|
25
|
+
"hivescope>=0.5.0a2",
|
|
26
|
+
"websockets>=11",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/JarbasHiveMind/HiveMind-HackChatBridge"
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
hivemind-hackchat-bridge = "hackchat_bridge.__main__:main"
|
|
34
|
+
|
|
35
|
+
[tool.setuptools]
|
|
36
|
+
packages = ["hackchat_bridge"]
|
|
37
|
+
include-package-data = true
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.dynamic]
|
|
40
|
+
version = { attr = "hackchat_bridge.version.__version__" }
|
|
41
|
+
dependencies = { file = ["requirements.txt"] }
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# HiveMind HackChat Bridge
|
|
2
|
+
|
|
3
|
+
Relay a [hack.chat](https://hack.chat) channel to a [HiveMind](https://github.com/JarbasHiveMind/HiveMind-core) hub.
|
|
4
|
+
|
|
5
|
+
[hack.chat](https://hack.chat) is a minimal, anonymous, channel-based websocket chat. This bridge is a HiveMind **satellite** whose input and output are a hack.chat channel instead of a microphone. Channel messages become utterances sent to the hub; the hub's spoken reply is posted back into the channel, addressed to the user. Any HiveMind hub (and the OVOS skills behind it) becomes a hack.chat bot.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
hack.chat channel ⇄ HiveMind-HackChatBridge ⇄ 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 **hack.chat channel name** to join, and a **nickname** for the bot. hack.chat is anonymous — no account or token is required.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install HiveMind-HackChatBridge
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or from a checkout:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/JarbasHiveMind/HiveMind-HackChatBridge
|
|
29
|
+
cd HiveMind-HackChatBridge
|
|
30
|
+
pip install .
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Declared dependencies: `hivemind-bus-client`, `ovos-bus-client`, `ovos-utils`, `websocket-client`, `click`.
|
|
34
|
+
|
|
35
|
+
## Quickstart
|
|
36
|
+
|
|
37
|
+
**1. Register the bridge on the hub** (where `hivemind-core` is installed):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
hivemind-core add-client --name hackchat-bridge \
|
|
41
|
+
--access-key "your-access-key" --password "your-password"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**2. Run the bridge.** Configuration is passed on the command line via the `hivemind-hackchat-bridge` console script (or `python -m hackchat_bridge`):
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
hivemind-hackchat-bridge \
|
|
48
|
+
--channel your_channel \
|
|
49
|
+
--username Jarbas_BOT \
|
|
50
|
+
--access-key "your-access-key" \
|
|
51
|
+
--password "your-password" \
|
|
52
|
+
--host ws://127.0.0.1 \
|
|
53
|
+
--port 5678
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**4. Send a message.** Open the same channel at `https://hack.chat/?your_channel` and type:
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
what time is it?
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The bridge forwards the message to the hub and posts the reply back as `@user , <answer>`.
|
|
63
|
+
|
|
64
|
+
## Configuration
|
|
65
|
+
|
|
66
|
+
`hivemind-hackchat-bridge` options:
|
|
67
|
+
|
|
68
|
+
| Option | Description | Default |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| `--channel` | hack.chat channel name to join | — (required) |
|
|
71
|
+
| `--username` | Bot nickname shown in the channel | `Jarbas_BOT` |
|
|
72
|
+
| `--host` | HiveMind hub host (`wss://` / `ws://`) | `ws://127.0.0.1` |
|
|
73
|
+
| `--port` | HiveMind hub port | `5678` |
|
|
74
|
+
| `--access-key` | HiveMind access key | `None` |
|
|
75
|
+
| `--password` | HiveMind password | `None` |
|
|
76
|
+
| `--self-signed` | Accept self-signed SSL certificates | off |
|
|
77
|
+
| `--lang` | Language code for utterances | `en-us` |
|
|
78
|
+
|
|
79
|
+
The bridge forwards every channel message except its own, stripping a leading `@username` mention of the bot before sending.
|
|
80
|
+
|
|
81
|
+
## Troubleshooting
|
|
82
|
+
|
|
83
|
+
- **Bot joins but never answers** — confirm the hub is reachable and the access key/password are registered (`hivemind-core list-clients`), and that the hub produces a `speak` for the answer.
|
|
84
|
+
- **Wrong channel** — the bot and the user must be on the same hack.chat channel name; open `https://hack.chat/?<channel>`.
|
|
85
|
+
|
|
86
|
+
## Documentation
|
|
87
|
+
|
|
88
|
+
- **[Operator setup](docs/operator-setup.md)** — hack.chat is anonymous (no account/token); registering the bridge on a HiveMind hub, the run command, and the network-only live e2e.
|
|
89
|
+
|
|
90
|
+
See also [`docs/`](docs/) for a full setup walkthrough, a configuration reference, and worked examples.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Smoke tests: import the package and construct the bridge without networking.
|
|
2
|
+
|
|
3
|
+
These tests must not touch the live hack.chat service or a HiveMind hub. The
|
|
4
|
+
HiveMessageBusClient is replaced by a fake bus, and ``HackChat`` (which opens a
|
|
5
|
+
websocket in its constructor) is only exercised lazily via ``connect_hackchat``,
|
|
6
|
+
which we do not call here.
|
|
7
|
+
"""
|
|
8
|
+
import hackchat_bridge
|
|
9
|
+
from hackchat_bridge import JarbasHackChatBridge, platform
|
|
10
|
+
from hackchat_bridge.version import __version__
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FakeBus:
|
|
14
|
+
"""Minimal stand-in for HiveMessageBusClient — records emits/handlers."""
|
|
15
|
+
|
|
16
|
+
def __init__(self):
|
|
17
|
+
self.emitted = []
|
|
18
|
+
self.mycroft_handlers = {}
|
|
19
|
+
|
|
20
|
+
def on_mycroft(self, msg_type, func):
|
|
21
|
+
self.mycroft_handlers[msg_type] = func
|
|
22
|
+
|
|
23
|
+
def emit(self, message):
|
|
24
|
+
self.emitted.append(message)
|
|
25
|
+
|
|
26
|
+
def run_forever(self): # pragma: no cover - never called in tests
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_version():
|
|
31
|
+
assert isinstance(__version__, str)
|
|
32
|
+
assert __version__
|
|
33
|
+
assert platform.startswith("JarbasHackChatBridge")
|
|
34
|
+
assert __version__ in platform
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_package_exports():
|
|
38
|
+
assert hasattr(hackchat_bridge, "JarbasHackChatBridge")
|
|
39
|
+
assert hasattr(hackchat_bridge, "HackChat")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_bridge_constructs_with_injected_bus():
|
|
43
|
+
bus = FakeBus()
|
|
44
|
+
bridge = JarbasHackChatBridge(username="Jarbas_BOT",
|
|
45
|
+
channel="test_channel",
|
|
46
|
+
bus=bus)
|
|
47
|
+
assert bridge.status == "disconnected"
|
|
48
|
+
assert bridge.hackchat is None
|
|
49
|
+
assert bridge.online_users == []
|
|
50
|
+
# speak/intent-failure handlers were registered on the bus
|
|
51
|
+
assert "speak" in bus.mycroft_handlers
|
|
52
|
+
assert "hive.complete_intent_failure" in bus.mycroft_handlers
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_send_to_hivemind_emits_utterance():
|
|
56
|
+
from ovos_bus_client import Message
|
|
57
|
+
|
|
58
|
+
bus = FakeBus()
|
|
59
|
+
bridge = JarbasHackChatBridge(username="Jarbas_BOT",
|
|
60
|
+
channel="test_channel",
|
|
61
|
+
bus=bus)
|
|
62
|
+
bridge.send_to_hivemind("what time is it", "alice")
|
|
63
|
+
assert len(bus.emitted) == 1
|
|
64
|
+
msg = bus.emitted[0]
|
|
65
|
+
assert isinstance(msg, Message)
|
|
66
|
+
assert msg.msg_type == "recognizer_loop:utterance"
|
|
67
|
+
assert msg.data["utterances"] == ["what time is it"]
|
|
68
|
+
assert msg.context["user"]["hackchat_username"] == "alice"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_handle_speak_routes_back_to_user(monkeypatch):
|
|
72
|
+
from ovos_bus_client import Message
|
|
73
|
+
|
|
74
|
+
bus = FakeBus()
|
|
75
|
+
bridge = JarbasHackChatBridge(username="Jarbas_BOT",
|
|
76
|
+
channel="test_channel",
|
|
77
|
+
bus=bus)
|
|
78
|
+
sent = []
|
|
79
|
+
|
|
80
|
+
class FakeHackChat:
|
|
81
|
+
def send_message(self, msg):
|
|
82
|
+
sent.append(msg)
|
|
83
|
+
|
|
84
|
+
bridge.hackchat = FakeHackChat()
|
|
85
|
+
msg = Message("speak", {"utterance": "it is noon"},
|
|
86
|
+
{"user": {"hackchat_username": "alice"}})
|
|
87
|
+
bus.mycroft_handlers["speak"](msg)
|
|
88
|
+
assert sent == ["@alice , it is noon"]
|