Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Botonic with Node v20 #2780

Merged
merged 46 commits into from
Mar 27, 2024
Merged

Botonic with Node v20 #2780

merged 46 commits into from
Mar 27, 2024

Conversation

Iru89
Copy link
Contributor

@Iru89 Iru89 commented Feb 9, 2024

Description

Removed from version 1.0.0-dev

  • botonic-api
  • botonic-pulumi
  • create-botonic-app package

Removes old AI packages that we won't update anymore

  • botonic-nlp
  • botonic-intent-classification
  • botonic-ner

Removes the package-lock.json from each package

Add the examples folder to the monorepo with the https://github.com/hubtype/botonic-examples but examples using @botonic/dx in the devDependencies and the new version of @botonic/react

With node 20 you use npm 10.
With npm 10 I created a monorepo using npm workspaces. With this monorepo you do npm install in the root of the project and this creates a shared node_modules in the root. You can run scripts for each package from the botonic root. For example npm run build -w @botonic/core

Change several things about how builds are done using tsc. It adds a tsconfig.esm.base.json and tsconfig.cjs.base.json to the root of the project and extends these two files to create the builds of all packages.

Context

This PR updates many dependencies such as Node, npm, webpack (webpack plugin), jest, eslint (eslint plugins), prettier, axios, etc.
It also updates the github actions so that builds are done properly when running tests in the repository.

Approach taken / Explain the design

When using an npm monorepo, symlink internal to the monorepo is used. When using symlink it is necessary to build @botonic/core before making changes to a package that requires @botonic/core.
For example if you want to change @botonic/react code you need to build @botonic/core to make the imports work, pass the lint, pass the tests etc.
This is also important in the github actions. now you can declare a BUILD_COMMAND for cases where you need to build core first.

To document / Usage example

To start developing using all these new versions of node, npm, monorepo, etc.

  • Remove all package-lock.json, all node_modules and lib folders
  • With nvm (or similar) use node 20 and npm 10
  • From root folder do an npm i
  • Then an npm build on @botonic/core
  • Then an npm build on @botonic/react

Testing

All the tests that already existed are still running locally and in the GitHub repository.

Update a @botonic/cli deploy.test.ts that used an example published in the master branch of the external @botonic-examples repository. Now use the examples folder inside the monorepo so that changes can be made and tests can be tested before releasing the example bot version.

Copy link

github-actions bot commented Feb 9, 2024

Test Results

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 6a5b5b3.

Copy link

github-actions bot commented Feb 9, 2024

Test Results

30 tests   30 ✅  4m 10s ⏱️
 6 suites   0 💤
 1 files     0 ❌

Results for commit 4321665.

♻️ This comment has been updated with latest results.

@Iru89 Iru89 force-pushed the node-v20 branch 4 times, most recently from f428c0d to 989fb8e Compare February 20, 2024 17:13
@Iru89 Iru89 marked this pull request as ready for review February 22, 2024 16:04
@Iru89 Iru89 marked this pull request as draft February 22, 2024 16:05
@Iru89 Iru89 marked this pull request as ready for review February 22, 2024 16:10
@Iru89 Iru89 marked this pull request as draft February 22, 2024 16:10
@Iru89 Iru89 force-pushed the node-v20 branch 18 times, most recently from 2b8654c to b6409ff Compare March 1, 2024 08:25
@Iru89 Iru89 requested review from ericmarcos, asastre and AinaVendrell and removed request for ericmarcos, asastre and AinaVendrell March 26, 2024 14:07
@Iru89 Iru89 marked this pull request as ready for review March 26, 2024 14:28
## Description

This PR for the moment is just a Draft to see how we could change the
functions to get the contents without using the UUID (in the code it is
called id) and use only the ContentID (in the code it is called code).

The idea is to have ContentID instead of UUID hardcoded in the bot code,
this way if the client deletes and recreates a node in the frontend of
the flow builder but puts the same ContentID the bot will still work the
same.

## Context

Use the `getContentsByContentID` function if you need to get content in
an action written in the bot code, instead of using the
`getContentsById`. The function `getContentsByContentID` can be useful
if you want to render a content in a custom message in webchat but not
in other channels like WhatsApp. For example in a rating action in
webchat you want a custom message to select the stars but in Whatsapp
you want it to be a normal message with buttons.

Add the function `getUUIDByContentID` that will allow to get the UUID of
a node using the ContentID. This is useful in case you need to pass the
UUID as a payload to the botonicInit function of the plugin-flow-builder
to do handoff, tracking, etc.

Make the `getContentsById` function private so that it cannot be called
from outside the plugin.

## Approach taken / Explain the design

You can no longer use the function getContentsById in the bot code, this
function becomes private, instead of this function you should use
getContentsByContentID.

If the BotAction node has a followUp instead of passing its followUpId
(UUID) as a payload parameter, the followUpContentID will be added and
using the getContentsByContentID function you can get the contents to
render.

## To document / Usage example

Example using a BotAction with followUp:  
```typescript
import {
  FlowBuilderActionProps,
  FlowBuilderMultichannelAction,
} from '@botonic/plugin-flow-builder'
import { RequestContext } from '@botonic/react'
import React from 'react'

import { BotRequest } from '../types'
import { getRequestData } from '../utils/actions'

interface RatingParms {
  value: number
  followUpContentID: string
}

export class TestRatingAction extends FlowBuilderMultichannelAction {
  static contextType = RequestContext
  static async botonicInit(
    request: BotRequest
  ): Promise<FlowBuilderActionProps> {
    const { cmsPlugin, botContext, payload } = getRequestData(request)
    const payloadParams = cmsPlugin.getPayloadParams<RatingParms>(payload)

    console.log('Do some logic with payloadParams', { payloadParams })

    const contents = await cmsPlugin.getContentsByContentID(
          payloadParams.followUpContentID,
          botContext.locale
        )

    return { contents }
  }
}

```

---------

Co-authored-by: Marc Rabat <35448568+vanbasten17@users.noreply.github.com>
@Iru89 Iru89 merged commit f038bce into master-lts Mar 27, 2024
5 checks passed
@Iru89 Iru89 deleted the node-v20 branch March 27, 2024 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants