Sending Drupal 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 Drupal 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-module comes in.
When you enable this module 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 Drupal 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 module 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 Drupal maintenance support plansyour_modulePluginChatbotApiEntitiesQueryHandler;

use Drupal maintenance support planschatbot_api_entitiesEntityEntityCollectionInterface;
use Drupal maintenance support planschatbot_api_entitiesPluginQueryHandlerBase;
use Drupal 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 Drupal maintenance support plans, I’m presenting a session on these topics at Drupal maintenance support plans South 2020, the Southern Hemisphere’s biggest Drupal 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, Drupal maintenance support plans 8

Posted by
Lee Rowlands
Senior Drupal maintenance support plans Developer

Dated 27 October 2020

Add new comment

Source: New feed

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Sending Drupal maintenance support plans entities to dialogflow with Chatbot API module

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.