GithubHelp home page GithubHelp logo

Comments (13)

markmanx avatar markmanx commented on May 28, 2024 26

@lackdaz is correct, but just to show a simpler example, say you have 2 steps like so:

...
{
      id: 'staticStep',
      component: <Button />,
      waitAction: true
},
{
      id: 'dynamicallyReachedStep',
      message: 'This step was reached dynamically.'
}

You can use the hook called triggerNextStep (which is passed as a prop to your dynamic component) to reach any step you want. So to reach the second step you could have a component like so:

const Button = props => (
      <button onClick={() => props.triggerNextStep({trigger: 'dynamicallyReachedStep'})}>
        Click me to go to the next step
      </button>
);

from react-simple-chatbot.

pravash02 avatar pravash02 commented on May 28, 2024 7

@lackdaz, Can you please give us an example of how you can add custom steps by reading user's input and then calling an API to interprete that and return a matching response from API

from react-simple-chatbot.

lackdaz avatar lackdaz commented on May 28, 2024 5

Hey just wanted to let you know that if you wanted to really use dynamic steps -- try passing the trigger via the TriggerNext function in custom components, it works and this is how I've managed to create 'dynamic' steps.

from react-simple-chatbot.

lackdaz avatar lackdaz commented on May 28, 2024 2

Hi @johncg182 , you can find the steps here: https://github.com/lackdaz/wdi-project4#reactsimplechatbot

And you can take a closer look at my codebase to see how its implemented. The trick is to pass your intended chat node as a trigger prop to the chatbot custom component that @LucasBassetti so elegantly provided. But just take note that longer conversations might run into memory issues.

from react-simple-chatbot.

lackdaz avatar lackdaz commented on May 28, 2024 2

the trick is to use custom components and the provided method triggetNext which overrides the the trigger specified when defining your steps.

Here is an example of how I used triggetNext to send the route to a step named 'Are you looking for a parcel? Sad' instead of the self.state.result which in this case was 'intent1'.

      if (tonesObj.Anger >= 0.5) {
        // this is the angry man condition
        self.setState({ loading: false, result: 'angry', show: 'Chill!' })
        self.triggetNext(self.state.result)
      }
      else if (entities && Object.keys(entities).length > 0 && entities.intent[0].value && tonesObj.Sadness >= 0.5) {
      self.setState({ loading: false, result: entities.intent[0].value })
      self.triggetNext('Are you looking for a parcel? Sad')
    }

and the step was defined as:

...
      {
        id: 'intent1',
        message: 'Hi {previousValue}!',
        trigger: 'intent'
      },
      {
        id: 'intent',
        component: <Wit_ai />,
        replace: true,
        waitAction: true,
        asMessage: true,
        trigger: 'askintent1'
      },
      {
        id: 'Are you looking for a parcel? Sad',
        message: 'I\'m sorry for your loss. We\'re trying our best to locate your parcel',
        trigger: 'Missing1'
      },
...

This way, you could get it to loop from intent to intent1 depending on your logical flow if that is your intent instead of having only a linear course for conversation.

I hope this was sufficiently clear!

from react-simple-chatbot.

LucasBassetti avatar LucasBassetti commented on May 28, 2024

Hi,

It is no possible create dynamic steps, but you can create a component step and render the content based on the previous steps. If you want render the component as a text message you can the element asMessage: true to that (Like this example).

from react-simple-chatbot.

johncg182 avatar johncg182 commented on May 28, 2024

Hi @lackdaz were you able to get your custom components to add dynamic steps over and over, as in continuing the conversation until the user signals an end? Can you show how you added your 'dynamic' steps...thanks!

from react-simple-chatbot.

GilbertMizrahi avatar GilbertMizrahi commented on May 28, 2024

@lackdaz, I looked at https://github.com/lackdaz/wdi-project4#reactsimplechatbot, but I don't see how you pass the trigger dynamically on a component.

Can you elaborate?

from react-simple-chatbot.

GilbertMizrahi avatar GilbertMizrahi commented on May 28, 2024

@lackdaz, I don't really get it.

I don't know how to use the triggerNextStep prop. It expects a value and a trigger. I know what I need for the trigger, but not for the value.

You mentioned the triggetNext method, but I don't see it in the documentation.

Do you have an example of using the triggerNextStep?

from react-simple-chatbot.

sangeetmukherjee avatar sangeetmukherjee commented on May 28, 2024

Hello @lackdaz and @LucasBassetti Just going through the ways of creating the steps array dynamic for react simple chatbot. The way you used is a simple user input object block. Can I use the same way for a dynamic Options Array where every time I will get the count different for the no of options to select. (As per the response)
Can any body assist me for the same......provided the snippet below

for(let i=0;i<this.props.actionArray.length;i++){
let item= {
value: this.props.actionArray[i],
label: this.props.actionArray[i],
trigger: (input) => {
this.props.eventHandler(input.value);
return this.props.trigger
}
}
actionItems.push(item);
}
dynamicAddInSteps = {
id:this.props.trigger,
options:actionItems
};

steps.push(dynamicAddInSteps);

from react-simple-chatbot.

sjain3097 avatar sjain3097 commented on May 28, 2024

Hey just wanted to let you know that if you wanted to really use dynamic steps -- try passing the trigger via the TriggerNext function in custom components, it works and this is how I've managed to create 'dynamic' steps.

any example?

from react-simple-chatbot.

louloub avatar louloub commented on May 28, 2024

@lackdaz is correct, but just to show a simpler example, say you have 2 steps like so:

...
{
      id: 'staticStep',
      component: <Button />,
      waitAction: true
},
{
      id: 'dynamicallyReachedStep',
      message: 'This step was reached dynamically.'
}

You can use the hook called triggerNextStep (which is passed as a prop to your dynamic component) to reach any step you want. So to reach the second step you could have a component like so:

const Button = props => (
      <button onClick={() => props.triggerNextStep({trigger: 'dynamicallyReachedStep'})}>
        Click me to go to the next step
      </button>
);

It's work for me thank you

from react-simple-chatbot.

Ganeshsharma36866 avatar Ganeshsharma36866 commented on May 28, 2024

HI @team

I'm using a custom header and using floating true. show's button on the bottom of the component and when i click on it a chat container is open . but don't know how I can minimize cross button click in the custom header component.

Please its urgent

from react-simple-chatbot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.