@botpress/client 0.26.5 → 0.28.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/client",
3
- "version": "0.26.5",
3
+ "version": "0.28.0",
4
4
  "description": "Botpress Client",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -30,7 +30,7 @@
30
30
  "type-fest": "^3.4.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@botpress/api": "0.38.3",
33
+ "@botpress/api": "0.39.0",
34
34
  "@types/qs": "^6.9.7",
35
35
  "esbuild": "^0.16.12",
36
36
  "lodash": "^4.17.21",
package/readme.md CHANGED
@@ -13,24 +13,33 @@ pnpm add @botpress/client # for pnpm
13
13
  ## Usage
14
14
 
15
15
  ```ts
16
- import { Client, ClientOutputs } from '@botpress/client'
16
+ import { Client } from '@botpress/client'
17
17
 
18
- type Bot = ClientOutputs['listBots']['bots'][number]
18
+ // 0. Type definitions for each operation's IO
19
+ type GetBotInput = ClientInputs['getBot']
20
+ type GetBotOutput = ClientOutputs['getBot']
19
21
 
20
22
  const main = async () => {
21
23
  const token = 'your-token'
22
24
  const workspaceId = 'your-workspace-id'
23
- const client = new Client({ token, workspaceId })
24
-
25
- const allBots: Bot[] = []
26
- let nextToken: string | undefined
27
- do {
28
- const resp = await client.listBots({ nextToken })
29
- nextToken = resp.meta.nextToken
30
- allBots.push(...resp.bots)
31
- } while (nextToken)
32
-
33
- console.log(allBots)
25
+ const botId = 'your-bot-id'
26
+ const client = new Client({ token, workspaceId, botId })
27
+
28
+ // 1. plain operations
29
+ const { bot } = await client.getBot({ id: botId })
30
+ console.log('### bot', bot)
31
+
32
+ // 2. list utils with `.collect()` function
33
+ const [latestConversation] = await client.list
34
+ .conversations({ sortField: 'createdAt', sortDirection: 'desc', integrationName: 'telegram' })
35
+ .collect({ limit: 1 })
36
+ console.log('### latestConversation', latestConversation)
37
+
38
+ // 3. list utils with async generator and `for await` syntax
39
+ for await (const message of client.list.messages({ conversationId: latestConversation.id })) {
40
+ console.log(`### [${message.userId}]`, message.payload)
41
+ }
34
42
  }
43
+
35
44
  void main()
36
45
  ```