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

plugin-flow-builder: bot action as follow up, first node in a flow, after conditionals etc #2898

Merged
merged 16 commits into from
Oct 1, 2024

Conversation

Iru89
Copy link
Contributor

@Iru89 Iru89 commented Sep 4, 2024

Description

Be able to use bot-action nodes at any point in the flow builder. For example as follow ups, after a conditional, at the start of a flow etc

The request.input should be immutable. To avoid modifying the request.input in the lambda execution, FlowBuilderAction.botonicInit function accepts as a second parameter the contentID to indicate which content has to be rendered. This contentID is the unique text that is defined in the flow builder frontend. This way you don't need to get the UUID of the content and modify the request.input.payload to indicate to the plugin which content to render.

Context

Bot-action nodes could only be used connected to a button or after a handoff.
With this solution it will be possible to make flow in a simpler way. There are several use cases in which the flow is greatly simplified by being able to put bot actions after a conditional or at the beginning of a flow.

Flow example:
Captura de pantalla 2024-09-03 a las 17 11 40

Approach taken / Explain the design

The third commit makes the core bot run again (prePlugins, routes, render, postPlugins). I think this should be the backend in charge of re-executing the lambda of the bot to avoid timeouts if the actions are asynchronous and more than one is chained. This way we would also avoid modifying the request.input.payload in a lambda execution.

IMPORTANT
With this change in the custom actions written in the flow it is necessary to obtain the following contents using the function FlowBuilderAction.botonicInit(request) since this is the one in charge of putting the variable in the session so that if there is another bot action connected to the flow, the bot will continue executing.

To document / Usage example

WelcomeAction example

export class WelcomeAction extends FlowBuilderMultichannelAction {
  static contextType = RequestContext
  static async botonicInit(
    request: BotRequest
  ): Promise<FlowBuilderActionProps> {
    const { cmsPlugin, botContext } = getRequestData(request)
    const contents = await cmsPlugin.getStartContents(botContext.locale)

     return FlowBuilderMultichannelAction.botonicInit(request, contents[0].code)
  }
}

Testing

For now I have not checked the tests, I am aware that they are failing.

packages/botonic-core/src/core-bot.ts Outdated Show resolved Hide resolved
packages/botonic-core/src/core-bot.ts Outdated Show resolved Hide resolved
@Iru89 Iru89 marked this pull request as ready for review September 5, 2024 13:21
Copy link
Contributor

@vanbasten17 vanbasten17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add at least a test for this new scenario 🙏

packages/botonic-core/src/models/legacy-types.ts Outdated Show resolved Hide resolved
packages/botonic-plugin-flow-builder/src/index.ts Outdated Show resolved Hide resolved
@Iru89 Iru89 marked this pull request as draft September 10, 2024 09:24
@Iru89 Iru89 marked this pull request as ready for review September 16, 2024 13:39
@Iru89 Iru89 force-pushed the plugin-flow-builder/bot-action-as-follow-up branch from d4eb071 to aa03d62 Compare October 1, 2024 15:58
Copy link

github-actions bot commented Oct 1, 2024

Test Results

30 tests   26 ✅  35s ⏱️
 6 suites   0 💤
 1 files     4 ❌

For more details on these failures, see this check.

Results for commit aa03d62.

♻️ This comment has been updated with latest results.

@Iru89 Iru89 merged commit ecdf404 into master-lts Oct 1, 2024
16 of 18 checks passed
@Iru89 Iru89 deleted the plugin-flow-builder/bot-action-as-follow-up branch October 1, 2024 16:02
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.

3 participants