Setup
How to set up a Wit integration
Wit is a free platform, made by Facebook, for building natural language experiences. With support for over 130 languages, Wit is particularly well-suited for apps that need to be available in multiple languages.
With Meya's Wit integration, you can:
- allow users to interact with your app using natural language,
- detect the user's intent and extract entities and traits from their text,
- trigger a flow using a Wit intent,
- use Wit components in your flows to collect user input and process it with Wit.
Keep reading to learn how to set up the integration.
Retrieve the server access token
First, let's retrieve your Wit app's server access token. Your Meya app will need this so it can make requests to Wit.
Navigate to your Wit dashboard and select your app. From the left-hand menu, choose Settings and copy the Server Access Token.
Update the vault
Now let's add the server access token as a secret in the app's vault.
In your Meya app's root folder, open vault.yaml
and add the following code to it:
wit.api_token: xxx
Recall that
vault.yaml
is committed to version control, so don't store actual secrets here; that's whatvault.secret.yaml
is for.
Now, open vault.secret.yaml
and copy this code into it:
wit.api_token: SERVER_ACCESS_TOKEN
Be sure to replace
SERVER_ACCESS_TOKEN
with your actual token.
Update your remote vault by running this command in your terminal:
meya vault upload --file vault.secret.yaml
Add the integration
Now we can create our integration file and reference the secret we just added to the vault.
In your app's integration
folder, create a new folder called facebook
. Inside the new folder create a file called wit.yaml
. Copy this code into it:
type: meya.facebook.wit.integration.integration
api_token: (@ vault.wit.api_token )
Add flows
Let's add some flows to test out the Wit trigger and components and make sure the integration is working properly.
Trigger
In your app's flow
folder, create a facebook
folder, then a wit
folder inside it. Create a file called trigger.yaml
inside the wit
folder and copy this code into it:
triggers:
- expect: wit
integration: integration.facebook.wit
intent_regex: weather
steps:
- say: Intent (@ flow.get("result") )
- say: Details (@ flow.get("wit_response") )
Lines 2 and 3: We tell the app to use the Wit trigger and to send the user's input to our Wit integration.
Using multiple Wit integrations
Depending on your use-case, you may want to connect multiple Wit apps to your Meya app. In that case, just be sure to specify in the trigger's
integration
property which integration is responsible for detecting this intent.
Line 4: We also specify a specific intent to expect. In this example, this flow will only be triggered if the intent is called weather
.
If you already have a Wit app with intents, update line 4 to one of your intents. Otherwise, you'll need to create the
weather
intent in your Wit app.
The rest of the flow prints the response from Wit so you can see what data is available to your Meya app.
Components
Inside the flow/facebook/wit
folder, create a file called component.yaml
and copy this code into it:
triggers:
- regex: ^wit.*$
action:
jump: (@ flow.result )
steps:
- (wit_form)
- ask_form: Enter NLU text
expect: wit
integration: integration.facebook.wit
retries: 1
min_confidence: 0.75
- jump: print
- (wit_composer)
- ask: Enter NLU text e.g. large size
expect: wit
integration: integration.facebook.wit
intent: size
- jump: print
- (wit_composer_no_catchall)
- ask: Enter NLU text e.g. large size
expect: wit
integration: integration.facebook.wit
retries: 1
min_confidence: 0.75
intent: size
catchall: false
- jump: print
- (wit_detect)
- detect_wit: large size
integration: integration.facebook.wit
min_confidence: 0.5
- jump: print
- (print)
- say: OK (@ flow.ok )
- say: Confidence (@ flow.get("confidence") )
- say: Intent (@ flow.get("result") )
- say: Details (@ flow.get("wit_response") )
Line 2: This flow can be triggered by saying wit_form
, wit_composer
, wit_composer_no_catchall
, or wit_detect
, and will jump directly to that label within the flow.
Lines 7 to 29: Wit is compatible with the ask and ask_form components.
The
catchall
propertyThe
ask
component hascatchall
set totrue
by default. This assigns a confidence value of1.0
to the user's input regardless of the confidence level returned by Wit.You can disable this by setting
catchall: false
and specifying amin_confidence
level that must be achieved in order to be accepted by the component. This is demonstrated in thewit_composer_no_catchall
steps.
Lines 32 to 35: The detect_wit
component let's your app send text to Wit. Unlike the other Wit components, detect_wit
is not an input component. The text can be hardcoded or passed in using a variable (e.g. - detect_wit: (@ user.issue )
).
To upload all of our changes to the Grid, run these commands in your terminal:
meya format
meya push
Test it out
Try triggering the trigger
flow with the phrase What is the weather tomorrow?
. The flow should return the weather
intent and the Wit response payload.
Test out the component
flow with the phrase wit_form
and make sure you get a result similar to this:
Great! You've successfully set up the Wit integration.
Updated about 2 years ago