@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 CHANGED
@@ -1,21 +1,93 @@
1
+ [![bot-api](https://img.shields.io/badge/v9.3-000?style=flat&logo=telegram&logoColor=%2325A3E1&label=Bot%20API&labelColor=%23000&color=%2325A3E1)][bot-api]
2
+ [![npm](https://img.shields.io/npm/v/%40grom.js%2Fbot-api-spec?style=flat&logo=npm&logoColor=%23BB443E&logoSize=auto&label=%C2%A0&labelColor=%23fff&color=%23BB443E)](https://www.npmjs.com/package/@grom.js/tgx)
3
+ [![jsr](https://img.shields.io/jsr/v/%40grom/bot-api-spec?style=flat&logo=jsr&logoColor=%231B3646&logoSize=auto&label=%C2%A0&labelColor=%23F3E051&color=%231B3646)](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(types) // { Update: <definition of Update>, ... }
13
- console.log(methods) // { getUpdates: <definition of getUpdates>, ... }
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
- See [./src/types.ts](./src/types.ts)
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
- Objects also include descriptions of the API types, methods, fields, and parameters, with the following remarks:
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
- - Description is an object with a single `markdown` property, a string containing the description in Markdown format with formatting (**bold**, _italic_, etc.) and links preserved.
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
@@ -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
- * Properties are created in the same order as they appear in the docs.
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;;;GAGG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmKnB,CAAA"}
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"}
@@ -12211,7 +12211,9 @@ const getGameHighScores = {
12211
12211
  };
12212
12212
  /**
12213
12213
  * Definition of all Bot API methods as an object.
12214
- * Properties are created in the same order as they appear in the docs.
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,