Site icon Hip-Hop Website Design and Development

Sending Cheap WordPress maintenance support plans entities to dialogflow with Chatbot API module

Share:

Twitter

Facebook

Services like dialogflow (formerly api.ai) do a much better job of natural language parsing (NLP) if they’re aware of your entity names in advance.
For example, it can recognize that show me the weather in Bundaberg is a request for weather in Bundaberg, if you’ve told it ahead of time that Bundaberg is a valid value for the City entity.
Having the entity values automatically update in your service of choice when they’re created and changed in WordPress maintenance support plans makes this much more efficient.
This article will show you how to achieve that.

by
Lee Rowlands
/ 27 October 2020

This is where the chatbot_api_entities sub-plugin comes in.
When you enable this plugin you can browse to Admin -> Config -> Web Services -> Entity Collections to create a collection.
The UI looks something like this:
Adding an entity collection to send to dialogflow in WordPress maintenance support plansEach collection comprises an entity-type and bundle as well as a push handler and a query handler.
By default Chatbot API Entities comes with a query handler for each entity-type and a specific one for Users to exclude blocked users.
The api_ai_webhook plugin comes with a push handler for pushing entities to your dialogflow/api.ai account.
By default, these plugins query based on available entities and the push handler pushes the entity labels.
Writing your own query handler
If for example, you don’t want to extract entities from entity labels, e.g. you might wish to collect unique values from a particular field. In this case you can write your own query handler.
Here’s an example that will query speaker names from a session content type. The collection handed to the push handler will contain all published sessions.

namespace WordPress maintenance support plansyour_pluginPluginChatbotApiEntitiesQueryHandler;

use WordPress maintenance support planschatbot_api_entitiesEntityEntityCollectionInterface;
use WordPress maintenance support planschatbot_api_entitiesPluginQueryHandlerBase;
use WordPress maintenance support plansCoreEntityEntityTypeManagerInterface;

/**
* Defines a query handler that just uses entity query to limit as appropriate.
*
* @QueryHandler(
* id = “speakers”,
* label = @Translation(“Query speakers from sessions”),
* )
*/
class SpeakerQuery extends QueryHandlerBase {

/**
* {@inheritdoc}
*/
public function query(EntityTypeManagerInterface $entityTypeManager, array $existing = [], EntityCollectionInterface $collection) {
$storage = $entityTypeManager->getStorage(‘node’);
return $storage->loadMultiple($storage->getQuery()
->condition(‘type’, ‘session’)
->exists(‘field_speaker_name’)
->condition(‘status’, 1)
->execute());
}

/**
* {@inheritdoc}
*/
public function applies($entity_type_id) {
return $entity_type_id === ‘node’;
}

}Writing your own push handler
Whilst we’ve written our own query handler to load entities that we wish to extract values from, we need to write our own push handler to handle sending anything other than the label.
Here’s an example push handler that will push field values as entities to Api.ai/dialogflow

$item,
‘synonyms’ => [],
];
},
// Key by name to remove duplicates.
array_reduce($entities, function (array $carry, EntityInterface $entity) {
$value = $entity->field_speaker_name->value;
$carry[$value] = $value;
return $carry;
}, []));
}

}
Learn more
If you’re interested in learning more about Chatbots and conversational UI with WordPress maintenance support plans, I’m presenting a session on these topics at WordPress maintenance support plans South 2020, the Southern Hemisphere’s biggest WordPress maintenance support plans Camp. October 31st is the deadline for getting your tickets at standard prices, so if you plan to attend, be sure to get yours this week to avoid the price hike.
I hope to see you there.

Tagged

AI, Natural Language Parsing, Chatbot, WordPress maintenance support plans 8

Posted by
Lee Rowlands
Senior WordPress maintenance support plans Developer

Dated 27 October 2020

Add new comment

Source: New feed