@Dannii I couldn’t respond inline because new users are limited to three replies per topic.
Sorry I haven’t been clear. At the risk of providing too much information, here’s a fairly complete description of what I’m trying to do.
I’m writing a Node.js application that has chat capabilities. My server is long running and may handle many chat sessions concurrently. In each session, the user is chatting with a chatbot. Users do not chat with each other.
Each user is a customer who has bought something from an online marketplace. The purpose of my chatbot is to supply answers to users’ queries about the status of their order(s), and perhaps provide options to escalate their case.
One way that I could implement the chatbot is to parse incoming chat messages and scan for known keywords such as “HELP” or “ORDER STATUS”. This would be fairly typical, abstract, limited and bland.
Instead, I was hoping to use IF to enrich the experience. Rather than talking abstractly to a chatbot, the customer enters an IF storyline starting in a room called “Support Desk” (or similar). In the room are placards or posters, or maybe a support agent NPC, etc. I haven’t worked out all the details.
Since the IF story is fully contained, I was going to do string replacement on command output to insert things like real order status details. String replacement was going to be my bridge between the static story world and the dynamic real world.
To use IF in this way, for each customer I need to:
- instantiate the interpreter and load the story,
- supply text to the interpreter on behalf of the user (incoming chat messages),
- retrieve the text the story produced,
- perform string replacement,
- post the final string back to the user (chat response).
(In addition I’ll probably want to save and load story state to recover from hiccups, but one thing at a time.)
What I’m looking for is a contained, native JS interpreter that I can instantiate many times in the same parent process, without side-effects (no use of argv, stdin/stdout, window, filesystem, etc.) and which offers an asynchronous, text in/text out API.
I understand that others have approached similar problems by spinning up a child process and then sending data through pipes. I could certainly look into firing up frotz or Glulx on a per-user or even per-chat-message basis. But given that Glk seems to be designed to provide an IF API, and that Quixe already exists, this seems closer to what I wanted.
I hope this makes sense!