The Dopt blocks JavaScript client is a friendly server-side package for accessing the Dopt blocks API to access and updates block and flow state for a particular user in Dopt.
It is published to npm as @dopt/blocks-javascript-browser-client
.
Via npm:
npm install @dopt/blocks-javascript-browser-client
Via Yarn:
yarn add @dopt/blocks-javascript-browser-client
Via pnpm:
pnpm add @dopt/blocks-javascript-browser-client
To configure the blocks JavaScript client you will need
- A blocks API key (generated in Dopt)
- A block uid
import { DoptApiClient } from '@dopt/blocks-javascript-browser-client';
const client = new DoptApiClient({
apiKey: process.env.DOPT_BLOCKS_API_KEY as string,
});
Get block data using the getBlock
method:
const block = await client.blocks.getBlock('model-block-1', {
version: 3,
userIdentifier: 'example-user-idenitifer',
});
Transition a block using the transition
method:
await client.blocks.transition('model-block-1', {
version: 3,
userIdentifier: 'example-user-identifier',
transitions: 'complete',
});
Get flow data using the getFlow
method:
const flow = await client.flows.getFlow('example-flow-identifier', {
version: 2,
userIdentifier: 'example-user-identifier',
});
Transition a flow using the flowIntent
method:
await client.flows.intent('example-flow-identifier', 'finish', {
version: 3,
userIdentifier: 'example-user-identifier',
});