@botonic/plugin-flow-builder 0.28.2-alpha.3 → 0.28.2-alpha.4
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 +58 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -61,8 +61,9 @@ npm install @botonic/plugin-flow-builder
|
|
|
61
61
|
import * as hubtypeFlowBuilder from '@botonic/plugin-flow-builder'
|
|
62
62
|
|
|
63
63
|
const flowBuilderOptions = {
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
apiUrl: 'HUBTYPE_FLOW_BUILDER_URL',
|
|
65
|
+
jsonVersion: 'latest',
|
|
66
|
+
getAccessToken: () => 'HUBTYPE_FLOW_BUILDER_ACCESS_TOKEN', // Used locally,
|
|
66
67
|
getLocale: () => 'YOUR_LOCALE',
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -79,16 +80,66 @@ By doing this, we are passing configuration parameters to the bot. This way we c
|
|
|
79
80
|
|
|
80
81
|
Below are the parameters that we can pass to the plugin:
|
|
81
82
|
|
|
82
|
-
- `
|
|
83
|
+
- `apiUrl`: This is the URL of the flow-builder API. The bot will automatically collect this URL, so in most cases, we don't have to pass it. It is used in cases where the Flow URL is in a testing environment.
|
|
84
|
+
|
|
85
|
+
- `jsonVersion`: This indicates which version of flow you want the bot to use. By default it will use the `latest` version which is what we want in production. We can set this to `draft` if we want the bot to use this content in a test environment.
|
|
83
86
|
|
|
84
87
|
- `flow`: In some situations, we may want to test a flow locally instead of using the Flow Builder service. To do this, we can define the flow and its corresponding tree of nodes in a JSON file and pass it to our plugin through this variable. By doing so, we can run and test our flow locally without relying on the external service.
|
|
85
88
|
|
|
86
89
|
- `customFunctions`: We are able to pass custom functions to the plugin by defining them in our code and then passing them as parameters. This allows us to extend the functionality of the plugin beyond its default capabilities and execute custom logic that is tailored to our specific needs. We can add custom functions in the frontend of the Flow Builder and pass them to the plugin through this variable.
|
|
87
90
|
|
|
88
|
-
- `getLocale`: We can pass
|
|
91
|
+
- `getLocale`: We can pass a locale value to the plugin to specify which language our bot will use.
|
|
89
92
|
|
|
90
93
|
- `getAccessToken`: When our bot is deployed in Hubtype, the plugin will automatically retrieve the access token. However, when testing our bot locally, we need to pass the access token as a variable.
|
|
91
94
|
|
|
95
|
+
- `trackEvent`: Using this option we can get the events generated in the plugin and track them in the platform we want.
|
|
96
|
+
|
|
97
|
+
e.g. using @botonic/plugin-hubtype-analytics.
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
trackEvent: async (request: BotRequest, eventName, args) => {
|
|
101
|
+
const htEventProps = {
|
|
102
|
+
action: eventName as EventAction,
|
|
103
|
+
...args,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
await hubtypeAnalytics.trackEvent(request, htEventProps)
|
|
108
|
+
} catch (error: any) {
|
|
109
|
+
console.error(error)
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
- `getKnowledgeBaseResponse`: Using this option we can inject a function so that the bot can respond to the user using a knowledge base.
|
|
115
|
+
|
|
116
|
+
e.g using @botonic/plugin-knowledge-bases
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
getKnowledgeBaseResponse: async (
|
|
120
|
+
request: BotRequest,
|
|
121
|
+
userInput: string,
|
|
122
|
+
sources: string[]
|
|
123
|
+
) => {
|
|
124
|
+
try {
|
|
125
|
+
const knowledgeBasePlugin = request.plugins.knowledgeBases
|
|
126
|
+
const response = await knowledgeBasePlugin.getInference(
|
|
127
|
+
request.session,
|
|
128
|
+
userInput,
|
|
129
|
+
sources
|
|
130
|
+
)
|
|
131
|
+
return response
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error(error)
|
|
134
|
+
return {
|
|
135
|
+
answer: '',
|
|
136
|
+
hasKnowledge: false,
|
|
137
|
+
sources: [],
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
```
|
|
142
|
+
|
|
92
143
|
2. Modify the `routes.ts` file, where routes map user inputs to actions which are in fact React Components:
|
|
93
144
|
|
|
94
145
|
```ts
|
|
@@ -123,7 +174,7 @@ e.g.
|
|
|
123
174
|
|
|
124
175
|
`webviews/flow-builder-webview-example/index.ts`
|
|
125
176
|
|
|
126
|
-
```
|
|
177
|
+
```ts
|
|
127
178
|
import {
|
|
128
179
|
createWebviewContentsContext,
|
|
129
180
|
FlowBuilderJSONVersion,
|
|
@@ -133,6 +184,7 @@ import { WebviewRequestContext } from '@botonic/react'
|
|
|
133
184
|
import React, { useContext, useState } from 'react'
|
|
134
185
|
|
|
135
186
|
import { Step1 } from './first-step'
|
|
187
|
+
import { Step2 } from './second-step'
|
|
136
188
|
|
|
137
189
|
const mapContents = {
|
|
138
190
|
textIntro: 'TEXT_INTRO',
|
|
@@ -189,7 +241,7 @@ In any component within the webview you can use the contents from the context
|
|
|
189
241
|
|
|
190
242
|
`webviews/flow-builder-webview-example/first-step.ts`
|
|
191
243
|
|
|
192
|
-
```
|
|
244
|
+
```ts
|
|
193
245
|
import React, { useContext } from 'react'
|
|
194
246
|
|
|
195
247
|
import { MyWebviewContentsContext } from './index'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.28.2-alpha.
|
|
3
|
+
"version": "0.28.2-alpha.4",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"description": "Use Flow Builder to show your contents",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@botonic/react": "0.28.2-alpha.
|
|
17
|
+
"@botonic/react": "0.28.2-alpha.4",
|
|
18
18
|
"axios": "^1.7.2",
|
|
19
19
|
"uuid": "^9.0.1"
|
|
20
20
|
},
|