@theopenbee/channel-sdk 0.1.0 → 0.2.0
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.
- package/LICENSE +21 -0
- package/README.md +5 -3
- package/dist/index.js +3 -0
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TENGYONGZHI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -47,13 +47,15 @@ defineChannel({
|
|
|
47
47
|
| `dataDir` | Private writable directory for this plugin |
|
|
48
48
|
| `mediaDir` | Directory where inbound attachments must be stored |
|
|
49
49
|
| `dispatch(msg)` | Hand an inbound message to openbee |
|
|
50
|
+
| `migrateChat(fromChatId, toChatId)` | Tell openbee a chat got a new id, so pending and running tasks follow it |
|
|
50
51
|
| `saveMedia(data, ext)` | Write an attachment into `mediaDir` and return its path |
|
|
51
52
|
| `log.debug/info/warn/error(message, fields?)` | Structured logs in the openbee log |
|
|
52
53
|
|
|
53
54
|
## Development
|
|
54
55
|
|
|
55
56
|
```sh
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
pnpm test
|
|
57
|
+
npm install
|
|
58
|
+
npm test
|
|
59
59
|
```
|
|
60
|
+
|
|
61
|
+
`npm install` also builds `dist/`; run `npm run build` after changing `src/`.
|
package/dist/index.js
CHANGED
|
@@ -74,6 +74,9 @@ export function defineChannel(def, io) {
|
|
|
74
74
|
dispatch: (message) => {
|
|
75
75
|
void peer.notify("inbound", message);
|
|
76
76
|
},
|
|
77
|
+
migrateChat: (fromChatId, toChatId) => {
|
|
78
|
+
void peer.notify("migrate_chat", { from_chat_id: fromChatId, to_chat_id: toChatId });
|
|
79
|
+
},
|
|
77
80
|
saveMedia: async (data, ext) => {
|
|
78
81
|
const suffix = ext ? (ext.startsWith(".") ? ext : "." + ext) : "";
|
|
79
82
|
const path = join(p.media_dir, `${Date.now()}-${randomBytes(4).toString("hex")}${suffix}`);
|
package/dist/types.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export interface ChannelContext {
|
|
|
60
60
|
mediaDir: string;
|
|
61
61
|
openbeeVersion: string;
|
|
62
62
|
dispatch(message: InboundMessage): void;
|
|
63
|
+
migrateChat(fromChatId: string, toChatId: string): void;
|
|
63
64
|
saveMedia(data: Uint8Array, ext: string): Promise<string>;
|
|
64
65
|
log: Logger;
|
|
65
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theopenbee/channel-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "SDK for building openbee channel plugins",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsc -p tsconfig.json",
|
|
35
35
|
"test": "node --test test/*.test.mjs",
|
|
36
|
-
"
|
|
36
|
+
"prepare": "npm run build"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^22.10.0",
|