@valuya/bot-channel-app-core 0.2.0-beta.1
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 +12 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +35 -0
- package/package.json +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Valuya
|
|
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
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @valuya/bot-channel-app-core
|
|
2
|
+
|
|
3
|
+
Shared inbound app helpers for gated bot-channel packages.
|
|
4
|
+
|
|
5
|
+
This package keeps channel-agnostic message-entry logic in one place:
|
|
6
|
+
|
|
7
|
+
- optional link-token interception before runtime handling
|
|
8
|
+
- generic inbound app orchestration
|
|
9
|
+
- reusable token extractors for common channel onboarding patterns
|
|
10
|
+
|
|
11
|
+
Transport-specific packages such as `@valuya/whatsapp-bot-channel` and
|
|
12
|
+
`@valuya/telegram-bot-channel` keep only their channel-specific wiring on top.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type LinkRedeemResult = {
|
|
2
|
+
linked: boolean;
|
|
3
|
+
reply: string;
|
|
4
|
+
code?: string;
|
|
5
|
+
};
|
|
6
|
+
export type InboundAppResult = {
|
|
7
|
+
reply: string;
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
export declare class BotChannelApp<TInboundArgs, TChannelArgs, TChannelResult, TLinkArgs> {
|
|
11
|
+
private readonly deps;
|
|
12
|
+
constructor(deps: {
|
|
13
|
+
channel: {
|
|
14
|
+
handleMessage(args: TChannelArgs): Promise<TChannelResult>;
|
|
15
|
+
};
|
|
16
|
+
linkResolver?: {
|
|
17
|
+
redeemLinkToken(args: TLinkArgs): Promise<LinkRedeemResult>;
|
|
18
|
+
};
|
|
19
|
+
extractLinkToken?: (args: TInboundArgs) => string | null;
|
|
20
|
+
buildLinkArgs?: (args: TInboundArgs, linkToken: string) => TLinkArgs;
|
|
21
|
+
buildChannelArgs: (args: TInboundArgs) => TChannelArgs;
|
|
22
|
+
getChannelReply: (result: TChannelResult) => string;
|
|
23
|
+
getChannelMetadata?: (result: TChannelResult) => Record<string, unknown> | undefined;
|
|
24
|
+
getLinkMetadata?: (result: LinkRedeemResult) => Record<string, unknown> | undefined;
|
|
25
|
+
});
|
|
26
|
+
handleInboundMessage(args: TInboundArgs): Promise<InboundAppResult>;
|
|
27
|
+
}
|
|
28
|
+
export declare function extractLinkCommandToken(body: string): string | null;
|
|
29
|
+
export declare function extractTelegramStartToken(body: string): string | null;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class BotChannelApp {
|
|
2
|
+
deps;
|
|
3
|
+
constructor(deps) {
|
|
4
|
+
this.deps = deps;
|
|
5
|
+
}
|
|
6
|
+
async handleInboundMessage(args) {
|
|
7
|
+
const linkToken = this.deps.extractLinkToken?.(args);
|
|
8
|
+
if (linkToken && this.deps.linkResolver && this.deps.buildLinkArgs) {
|
|
9
|
+
const result = await this.deps.linkResolver.redeemLinkToken(this.deps.buildLinkArgs(args, linkToken));
|
|
10
|
+
return {
|
|
11
|
+
reply: result.reply,
|
|
12
|
+
metadata: this.deps.getLinkMetadata?.(result),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const result = await this.deps.channel.handleMessage(this.deps.buildChannelArgs(args));
|
|
16
|
+
return {
|
|
17
|
+
reply: this.deps.getChannelReply(result),
|
|
18
|
+
metadata: this.deps.getChannelMetadata?.(result),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function extractLinkCommandToken(body) {
|
|
23
|
+
const value = String(body || "").trim();
|
|
24
|
+
if (!value)
|
|
25
|
+
return null;
|
|
26
|
+
const match = value.match(/(?:^|\s)LINK\s+(gls_[A-Za-z0-9]+)/i);
|
|
27
|
+
return match?.[1] || null;
|
|
28
|
+
}
|
|
29
|
+
export function extractTelegramStartToken(body) {
|
|
30
|
+
const value = String(body || "").trim();
|
|
31
|
+
if (!value)
|
|
32
|
+
return null;
|
|
33
|
+
const match = value.match(/^\/start(?:@\w+)?\s+(gls_[A-Za-z0-9]+)/i);
|
|
34
|
+
return match?.[1] || null;
|
|
35
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@valuya/bot-channel-app-core",
|
|
3
|
+
"version": "0.2.0-beta.1",
|
|
4
|
+
"description": "Shared inbound app helpers for gated bot-channel packages",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^25.0.10"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"tag": "next"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
28
|
+
"test": "pnpm run build && node --test dist/*.test.js"
|
|
29
|
+
}
|
|
30
|
+
}
|