Two ways in.
Paste one script tag for a website. For an app, read one published file and match what people say yourself.
Website widget
Add this before </body>. A “Hey Sharkie!” button appears and answers with your words and your voice. The script is about 17 KB.
<script src="https://console.sharkie.in/widget/sharkie.js"
data-app="your-workspace" async></script>
Options
Only data-app is required. Anything else is a data- attribute on the same tag.
data-app | Required. The workspace id (the console shows yours on Integrate). |
|---|---|
data-lang | en or hi. The language of the answers it shows and speaks. |
data-side | right (default) or left: which corner the button sits in. |
data-label | The button’s words. Default “Hey Sharkie!”. |
data-title | The title of the chat window. |
data-accent | A hex colour, for example #8d7ce8. Default is indigo. |
data-theme | auto (default), light or dark. |
data-greeting | What it says when opened. |
data-unknown | What it says when it did not understand. |
data-speak | Set to false to show answers without playing the voice. |
data-bottom, data-side-offset | Distance from the bottom and the side, in pixels. |
data-routes | JSON that maps an “open” intent’s target to a URL on your site. |
data-api | Only if you run your own Sharkie Worker. |
From script
Sharkie.init({ app: 'your-workspace' }) // or pass a manifest you already fetched
Sharkie.open()
Sharkie.close()
Sharkie.ask('what time is the class')
Sharkie.destroy()
Events
The widget is a <sharkie-widget> element and fires bubbling events your page can listen for.
document.addEventListener('sharkie:answer', (e) => console.log(e.detail)) // { text, intent, line }
document.addEventListener('sharkie:action', (e) => console.log(e.detail)) // { name, kind, target, arg, href }
document.addEventListener('sharkie:unknown', (e) => console.log(e.detail)) // { text }
sharkie:action fires when an intent opens a page or does something in the page. sharkie:unknown fires when nothing matched, a good place to log what people ask for.
Your own app
Publishing in the console makes a release. Your app reads the newest one:
GET https://console.sharkie.in/v1/manifest/your-workspace
The answer is cached for 60 seconds and carries an ETag, so asking again is cheap. It has the intents with their phrases, the lines Sharkie says, and the hash of each voice recording:
{
"app": "your-workspace",
"version": 12,
"intents": {
"class_times": {
"kind": "answer",
"target": "",
"phrases": ["what time is the class", "any class tonight"],
"line": "class_times_1"
},
"open_classes": {
"kind": "open",
"target": "classes",
"phrases": ["show me the classes"]
}
},
"lines": { "class_times_1": ["Yes, Vinyasa at 7:30.", "हाँ, ..."] },
"clips": { "class_times_1": { "en": "<hash>" } }
}
Match what a person says against each intent’s phrases (the widget does this with edit distance and shared words; its matcher is open to read in the widget source). For a match, show the line and play its recording:
GET https://console.sharkie.in/v1/clip/your-workspace/class_times_1.en.mp3?h=<hash>
Both addresses are public and open to other origins, so they work from a browser, a phone app or a server. The recording is immutable when the hash matches, so cache it for good.
Intent kinds
answer says a line. open names a screen or page (target) your app should go to. Other kinds, such as built-in actions, carry a target and an optional arg taken from the sentence.