@grom.js/bot-api-spec 0.5.0 → 0.6.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/README.md +85 -9
- package/dist/methods.gen.d.ts +3 -1
- package/dist/methods.gen.d.ts.map +1 -1
- package/dist/methods.gen.js +3 -1
- package/dist/methods.gen.js.map +1 -1
- package/dist/types.gen.d.ts +3 -1
- package/dist/types.gen.d.ts.map +1 -1
- package/dist/types.gen.js +3 -1
- package/dist/types.gen.js.map +1 -1
- package/package.json +1 -1
- package/src/methods.gen.ts +3 -1
- package/src/types.gen.ts +3 -1
package/README.md
CHANGED
|
@@ -1,21 +1,93 @@
|
|
|
1
|
+
[][bot-api]
|
|
2
|
+
[](https://www.npmjs.com/package/@grom.js/tgx)
|
|
3
|
+
[](https://jsr.io/@grom/tgx)
|
|
4
|
+
|
|
1
5
|
[Telegram Bot API](https://core.telegram.org/bots/api) specification as a collection of JavaScript objects in a [custom format](#format).
|
|
2
6
|
|
|
3
7
|
## Motivation
|
|
4
8
|
|
|
5
9
|
Automatically generate tools, libraries, MCP servers, custom documentations, etc.
|
|
6
10
|
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
# Using npm
|
|
15
|
+
npm install @grom.js/bot-api-spec
|
|
16
|
+
|
|
17
|
+
# Using JSR
|
|
18
|
+
deno add jsr:@grom/bot-api-spec
|
|
19
|
+
```
|
|
20
|
+
|
|
7
21
|
## Usage
|
|
8
22
|
|
|
23
|
+
Root module exports two objects:
|
|
24
|
+
|
|
25
|
+
1. `types` — definition of all Bot API types
|
|
26
|
+
2. `methods` — definition of all Bot API methods
|
|
27
|
+
|
|
9
28
|
```ts
|
|
10
|
-
import { types, methods } from '@grom.js/bot-api-spec'
|
|
29
|
+
import { types, methods } from '@grom.js/bot-api-spec' // '@grom/bot-api-spec' for JSR
|
|
30
|
+
|
|
31
|
+
console.log(types)
|
|
32
|
+
// {
|
|
33
|
+
// Update: {
|
|
34
|
+
// name: 'Update',
|
|
35
|
+
// description: { markdown: '...' },
|
|
36
|
+
// fields: [
|
|
37
|
+
// {
|
|
38
|
+
// name: 'update_id',
|
|
39
|
+
// type: { type: 'int32' },
|
|
40
|
+
// description: { markdown: '...' },
|
|
41
|
+
// required: true,
|
|
42
|
+
// },
|
|
43
|
+
// ...
|
|
44
|
+
// ],
|
|
45
|
+
// },
|
|
46
|
+
// ...
|
|
47
|
+
// }
|
|
11
48
|
|
|
12
|
-
console.log(
|
|
13
|
-
|
|
49
|
+
console.log(methods)
|
|
50
|
+
// {
|
|
51
|
+
// getUpdates: {
|
|
52
|
+
// name: 'getUpdates',
|
|
53
|
+
// description: { markdown: '...' },
|
|
54
|
+
// parameters: [
|
|
55
|
+
// {
|
|
56
|
+
// name: 'offset',
|
|
57
|
+
// type: { type: 'int32' },
|
|
58
|
+
// description: { markdown: '...' },
|
|
59
|
+
// required: false,
|
|
60
|
+
// },
|
|
61
|
+
// ...
|
|
62
|
+
// ],
|
|
63
|
+
// returnType: {
|
|
64
|
+
// type: 'array',
|
|
65
|
+
// of: {
|
|
66
|
+
// type: 'api-type',
|
|
67
|
+
// name: 'Update',
|
|
68
|
+
// },
|
|
69
|
+
// },
|
|
70
|
+
// },
|
|
71
|
+
// ...
|
|
72
|
+
// }
|
|
14
73
|
```
|
|
15
74
|
|
|
16
75
|
## Format
|
|
17
76
|
|
|
18
|
-
|
|
77
|
+
Refer to the [./src/format.ts](./src/format.ts) module for reference.
|
|
78
|
+
|
|
79
|
+
You can also import types in your code:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import type { ValueType } from '@grom.js/bot-api-spec/format' // '@grom/bot-api-spec/format' for JSR
|
|
83
|
+
|
|
84
|
+
function generateCode(valueType: ValueType): string {
|
|
85
|
+
if (valueType.type === 'str') {
|
|
86
|
+
return 'string'
|
|
87
|
+
}
|
|
88
|
+
// ...
|
|
89
|
+
}
|
|
90
|
+
```
|
|
19
91
|
|
|
20
92
|
### Value Types
|
|
21
93
|
|
|
@@ -36,9 +108,13 @@ Below are the rules how we map type of a field/parameter to the `ValueType`:
|
|
|
36
108
|
|
|
37
109
|
### Descriptions
|
|
38
110
|
|
|
39
|
-
|
|
111
|
+
All definitions of types, methods, fields, and parameters include their descriptions.
|
|
112
|
+
|
|
113
|
+
Descriptions are copied verbatim from the official [Bot API documentation][bot-api], with the following modifications:
|
|
114
|
+
|
|
115
|
+
- Description HTML is parsed and converted to Markdown.
|
|
116
|
+
- The "_Optional._" prefix is omitted from field descriptions. Instead, the `required` property is set to `false` for such fields.
|
|
117
|
+
- "JSON-serialized..." portions are omitted from field/parameter descriptions.
|
|
118
|
+
- "...may have more than 32 significant bits...but it has at most 52 significant bits..." portions are omitted from _Integer_ field/parameter descriptions. Instead, the `type` is set to `int53` for such fields/parameters (as per [TDLib](https://core.telegram.org/tdlib/docs/td__api_8h.html#a6f57ab89c6371535f0fb7fec2d770126)).
|
|
40
119
|
|
|
41
|
-
-
|
|
42
|
-
- "_Optional._" prefix in field descriptions is omitted; instead, the `required` property is set to `false` for such fields.
|
|
43
|
-
- "JSON-serialized..." in field/parameter descriptions is omitted; instead, the `jsonSerialized` property is set to `true` for such fields/parameters.
|
|
44
|
-
- "...may have more than 32 significant bits...but it has at most 52 significant bits..." in _Integer_ field/parameter descriptions is omitted; instead, `type` is set to `int53` for such fields/parameters (as per [TDLib](https://core.telegram.org/tdlib/docs/td__api_8h.html#a6f57ab89c6371535f0fb7fec2d770126)).
|
|
120
|
+
[bot-api]: https://core.telegram.org/bots/api
|
package/dist/methods.gen.d.ts
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
import type { ApiMethod } from './format.ts';
|
|
7
7
|
/**
|
|
8
8
|
* Definition of all Bot API methods as an object.
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
|
+
* Properties are defined in the same order as they appear in the
|
|
11
|
+
* {@link https://core.telegram.org/bots/api Telegram Bot API documentation}.
|
|
10
12
|
*/
|
|
11
13
|
export declare const methods: {
|
|
12
14
|
getUpdates: ApiMethod;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"methods.gen.d.ts","sourceRoot":"","sources":["../src/methods.gen.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAklY5C
|
|
1
|
+
{"version":3,"file":"methods.gen.d.ts","sourceRoot":"","sources":["../src/methods.gen.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAklY5C;;;;;GAKG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmKnB,CAAA"}
|
package/dist/methods.gen.js
CHANGED
|
@@ -12211,7 +12211,9 @@ const getGameHighScores = {
|
|
|
12211
12211
|
};
|
|
12212
12212
|
/**
|
|
12213
12213
|
* Definition of all Bot API methods as an object.
|
|
12214
|
-
*
|
|
12214
|
+
*
|
|
12215
|
+
* Properties are defined in the same order as they appear in the
|
|
12216
|
+
* {@link https://core.telegram.org/bots/api Telegram Bot API documentation}.
|
|
12215
12217
|
*/
|
|
12216
12218
|
export const methods = {
|
|
12217
12219
|
getUpdates,
|