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.
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.
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:
vault.yamlis committed to version control, so don't store actual secrets here; that's what
vault.secret.yaml and copy this code into it:
Be sure to replace
SERVER_ACCESS_TOKENwith your actual token.
Update your remote vault by running this command in your terminal:
meya vault upload --file vault.secret.yaml
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
wit.yaml. Copy this code into it:
type: meya.facebook.wit.integration.integration api_token: (@ vault.wit.api_token )
Let's add some flows to test out the Wit trigger and components and make sure the integration is working properly.
In your app's
flow folder, create 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
integrationproperty 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
If you already have a Wit app with intents, update line 4 to one of your intents. Otherwise, you'll need to create the
weatherintent 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.
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_detect, and will jump directly to that label within the flow.
trueby default. This assigns a confidence value of
1.0to the user's input regardless of the confidence level returned by Wit.
You can disable this by setting
catchall: falseand specifying a
min_confidencelevel that must be achieved in order to be accepted by the component. This is demonstrated in the
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
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 4 months ago