Quick definition and usage of custom function

This example shows how one can

  1. program a weather forecast search function (weather),
  2. define a command name to function mapping, and then
  3. start JustSayIt using these customly defined commands.

The command weather programmed here allows to find out how the weather is today or tomorrow - just say "weather today" or "weather tomorrow". Furthermore, if you say "help weather", it will show in the Julia REPL the function documentation written here. To run this example, type in the Julia REPL include("path-to-file") or simply copy-paste the code below inside (the corresponding file can be found here).

# To run this do in the Julia REPL `include("path-to-file")` or simply copy paste it inside.
using JustSayIt
using JustSayIt.API       # Import JustSayIt API to write @voicearg functions
using DefaultApplication  # To install type: `]` and then `add DefaultApplication`

# 1) Define a custom weather forecast search function.
@doc """
    weather `today` | `tomorrow`

Find out how the weather is `today` or `tomorrow`.
"""
weather
@enum Day today tomorrow
@voiceargs day=>(valid_input_auto=true) function weather(day::Day)
    DefaultApplication.open("https://www.google.com/search?q=weather+$day")
end

# 2) Define command name to function mapping, calling custom function
commands = Dict("help"      => Help.help,
                "weather"   => weather,
                );

# 3) Start JustSayIt with the custom commands.
start(commands=commands)  # If you say "help weather", it will show the documentation written above in the Julia REPL.