Building a directed graph from Voiceflow (json)

102 Views Asked by At

I have built a chatbot in Voiceflow and I want to be able to map the dialogue in an interactive way to demonstrate every path a user could take. I am intending to use a directed graph from something like networkx, but I am not sure how to parse the JSON file I get from Voiceflow. A demo of my chatbot is as follows:

ROOT

Option 1

Option 2

A link to the JSON file I am testing this with is available here

As far as I can tell, all the information I need is stored in the "diagrams" key. Each diagram in diagrams is an individual page/topic. I have three, corresponding to each of the images above. Within each diagram are nodes, containing more information such as the text displayed, child paths, the block ID, next steps etc.

The problem I have is that I can't work out how to map the text elements (which would be the nodes in the graph), with the information that would act as the edges (button options, goto blocks).

I've managed to get a somewhat usable output with the below code, which has helped me understand the structure a little easier, but I'm no closer to building the actual graph.

with open('data/test_dialogue.vf') as f:
    data = json.load(f)


def parse_diagrams(json_string):
    for diagram_id, diagram in data["diagrams"].items():
        print(f'Diagram ID: {diagram_id}, Name: {diagram["name"]}')
        for node_id, node in diagram["nodes"].items():
            print(f'  Node ID: {node_id}, Type: {node["type"]}')
            if 'data' in node:
                print(f'    Data: {node["data"]}')

0

There are 0 best solutions below