Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Latest commit

 

History

History
80 lines (62 loc) · 2.02 KB

ai.md

File metadata and controls

80 lines (62 loc) · 2.02 KB

Artifical Intelligence

This module provide you easy access to api.ai to build your Siri-like bot.

Before begin we recommend to read api.ai documentation first and understand basic principes.

interface AiTrait {
    var aiSubscriptionKey: String?
    fun registerAiAgent(key: String, lang: String, token: String)
    fun aiQuery(query: String): AiResponse?
    fun aiQuery(query: String, closure: AiResponse.() -> Unit)
    fun aiQuery(agent: String, query: String): AiResponse?
    fun aiQuery(agent: String, query: String, closure: AiResponse.() -> Unit)
}

Query Response

class AiResponse {
    val raw: JSONObject
    val action: String
    val speech: String?

    val pQuery: String?
    val pSimplified: String?
    val pRequestType: String?
    val pSummary: String?
    val pTime: Date?
}

raw - Raw Response from API.AI action - Recognized action name speech - Suggested text response

pQuery - query parameter for some actions (like searching on the web) pSimplified - simplified input string. For example, "hi", "hello", "nice to meet you!" will be simplified to "hello" pRequestType - type of request (domain or agent) pSummary - summary of input string pTime - recognized time

Configuration

Before using ai methods you need to provide subscription key and register your agents. Module can work with multiple agents. First registered agent is considered as default.

aiSubscriptionKey = "<YOUR_SUBSCRIPTION_KEY>"
registerAiAgent("<agent_id>", "<agent_lang>", "<agent_key>")

Queries

Performing AI query

fun aiQuery(query: String): AiResponse?
fun aiQuery(agent: String, query: String): AiResponse?

Query with closure

fun aiQuery(query: String, closure: AiResponse.() -> Unit)
fun aiQuery(agent: String, query: String, closure: AiResponse.() -> Unit)

Same as above, but provide nice syntax like:

aqQuery(text) {
	when(action) {
		"smalltalk.greetings" -> {
			sendText("Hello!")
		}
	}
}