Here's a video-tutorial:
Step 1: Go to your world-folder/data/functions and create a folder named npcspeak. In that folder, create a file named main.mcfunction
Step 2: Click on the button 'get basic commands' below and copy the text. Open the main.mcfunction-file with a text editor and paste it.
Step 3: Create your dialogue with the scratch programm. Follow the instructions in there. Copy the output.
Step 4: Paste the text into the textbox saying 'Paste the output here:' and press Finish. Copy the commands (NOT the part saying not to copy it into a function)
Step 5: Go to your main.mcfunction-file and replace 'REPLACE THIS WITH YOUR COMMANDS' with the commands you got. To add more conversations, paste the commands you create under the commands you have just added.
Step 6: In your Minecraft world, enter /reload and /gamerule gameLoopFunction npcspeak:main
Step 7: Now you can spawn the villager. The command for the spawn egg is right below the commands you've copied earlier. Right-click the villager to start the conversation.