Skip to content

Ava.intent()

Javi Jiménez edited this page Jun 25, 2016 · 2 revisions

The purpose of this method is teach Ava about what kind of things can answer you. As you read in the introduction the core of ava use Intents and Actions which are simple functions than receiving a state and return it with an internal composition.

The method intent is chainable that means you can attach all the intents you need, more intents means Ava is more inteligent 😉. This method takes two parameters:

  • intent: the function you wanna attach
  • actions: an action function (or Array of functions) those will call if the intent is is satisfactorily resolved.
import { weather } from `ava-ia/lib/intents`;
import { forecastYahoo } from `ava-ia/lib/actions`; 

ava.intent(weather, forecastYahoo);

If we want attach two actions for the same intent just write:

import { forecastYahoo, forecastMSN } from `ava-ia/lib/actions`; 

ava.intent(weather, [forecastYahoo, forecastMSN]);

Ava will wait for the first successful action, that means like it's a race between the actions of a determinate intent and wins which finish first. If you wanna create a chain of intents it's quite easy:

import { weather, movie } from `ava-ia/lib/intents`;
import { forecastYahoo, movieDB } from `ava-ia/lib/actions`;

ava
  .intent(weather, forecastYahoo)
  .intent(movie, movieDB);

Feel free to offer new features, improvements or anything you can think of. This project makes sense with your participation and experience using Ava.

Clone this wiki locally