Note: this post is probably of low interest. I am simply making a record of some little personal projects I have made.
My personal motivation for this project was to learn about voice assistants. The actual project goal, however, was to produce a dice calculation voice assistant feature that understood the ins-and-outs of D&D 5e. I wanted to be able to say “with advantage”, apply modifiers, and even reference spells.
Dice Calculator was a “Conversational Action” on Google Assistant, which meant you could say “Hey Google, talk to Dice Calculator” to invoke it. A single intent dispatched all requests via Dialogflow to a app running in Google Cloud Run.
This app parsed the request using a grammar that was part manually specified and part generated from a database of D&D 5e spells and weapons. The parsed tree then went through a series of transformations, for example transforming advantage (a D&D concept) into the max of two copies of whatever was being done with advantage. The final transformation actually rolls dice and does arithmetic, resulting in the final answer.
This final answer was then composed into a dialog response, and sent back to the user.
The code is on github at https://github.com/davidn/dice-calculator
Dialogflow webhook fulfillment is documented as a JSON API. However, knowing that Google uses protobuf internally and wanting to use structured serialization/deserialization, I found and used the protobuf definitions with protobuf json_format. This may have been a mistake, as the protobuf library is large and resulted in slow cold-starts in Google Cloud Run, causing a long tail latency.
For debugging, the code is instrumented with Google Cloud Trace & Logs allowing easily seeing the inner workings of each request:
For monitoring, I used a Google Cloud Monitoring uptime check which invokes a Google Cloud Function endpoint which in turn makes a full request to the Cloud Functions app, and checks the result. This is needed because a simple uptime check directly to the app would not contain a valid request nor check the validity of the response.
Sadly Google is shutting down the ability for developers to provide custom conversation agents with Google Assistant, so Dice Calculator is no longer operational.