retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
10.17k stars 653 forks source link

How to Create Nodes with dynamic names and get output reference? #457

Closed CosmicSnow closed 4 years ago

CosmicSnow commented 4 years ago

Ok, I have a educational project where I need to create a bot using a nonSQL DB (firebase, mongodb etc). I'll try my best to explain what I'm trying to do:

So, I have a chat bot, where it's structure is object oriented, where the object names matters, and each object is composed by, A Text and it's next steps. All object steps are structured the same way.

example of S Objects (S is just a prefix for the object name):

s0: {
      text: "Hello and welcome to botchat."
      nextStep: {
                      "1": { description: "show Website link", target: "s1"}
                      "2": { description: "end chat", target: ""}
                      }
}
s1: {
      text: "some website here."
      nextStep: {}
}

I have a backend to treat it, so don't really mind so much how it works, So, what I am trying to do is create a Node where it acts like these S Objects. I tried some ways, but didn't get it working as intended..

My questions are,

How to make an Node take an Output connection and read it's destination, so it can make a reference to this destination node inside the nextStep object (inside target).

And is there a way to make nodes get a unique name? if there's only one S Node, it's name should be s0, and every new object inserted should be named with a new number, like s1, s2, s3, s4...

I didn't figure out how to do it with rete, maybe I could invert output and input (I mean, their CSS's, their positions) so I could take a reference of the last object, and pass the information I want, since output can't have controllers. Well, I hope someone can help me with this, it's been frustrating to make it work..

Ni55aN commented 4 years ago

And is there a way to make nodes get a unique name?

Node name must be predefined (like function name in programming languages)

How to make an Node take an Output connection and read it's destination

editor.toJSON() returns scheme where you can find output -> connections properties

so it can make a reference to this destination node inside the nextStep object (inside target).

This is done inside Rete.Engine when processing. I think you should convert your schema to compatible Rete.js scructure

CosmicSnow commented 4 years ago

thank you for your answear @Ni55aN, It helped a lot!

One last question, is it possible to make outputs with user inputs? Like, a box for a string input, with an output socket on the right, So I could connect an option from the bot to the a next node.

Thanks in advance!

creadicted commented 4 years ago

@CosmicSnow Have you seen this: https://codepen.io/hatead1/pen/GaZYaq

CosmicSnow commented 4 years ago

@CosmicSnow Have you seen this: https://codepen.io/hatead1/pen/GaZYaq

didn't see this, thank you very much! :) I'll try to make these outputs on the right side of the text.

Thanks!

creadicted commented 4 years ago

@CosmicSnow for what renderer are you working on this sample? If you get a component with that working - mind to share? Then we could increase some demos in the examples repo.

CosmicSnow commented 4 years ago

@creadicted I am using Angular. I'll probably just use css to control the input box and output socket positions, so they stay aligned. And about the input box, I'll try to read info from the input and place it in a variable, and the socket outputs this variable, I don't know how to do this part yet (not using rete) but I think it will work.

If I get it working, I can share it! No problems

carl-jin commented 3 years ago

@creadicted I am using Angular. I'll probably just use css to control the input box and output socket positions, so they stay aligned. And about the input box, I'll try to read info from the input and place it in a variable, and the socket outputs this variable, I don't know how to do this part yet (not using rete) but I think it will work.

If I get it working, I can share it! No problems

could u share that for us?