Custom Intent
The basic and most common scenario is an intent returning a custom message.
Let's pretend our Alexa Skill and/or Dialogflow Agent has the utternace "Say Hello to the World" mapped to the intent HelloWorld.
The requirement want the intent 'HelloWorld' should always return the message "Hello from Chatbot API, today is Monday, 1st January 2001", where the date must be today.
The first task is to create a Chatbot Intent plugin and using HelloWorld as plugin ID (plugin IDs are intents names).
You can create this manually following the helloworld_intent example submodule, but the quickest way is to use the Drupal Console integration:
drupal generate:plugin:chatbotintentAs long as you use HelloWorld as plugin ID, the rest of the details - the plugin label, the module the plugin belongs to, etc - are up to you.
We now have our plugin up and running, but if you send a request you'll probably get an empty response (or an error, depending by the cases). This is because the plugin process() method needs the logic.
public function process() {
$this->response->setIntentResponse('Hello from Chatbot API, today is ' . date('l, jS F Y'));
}This is what our intent response should be. Try now and you should hear the right message.
Feel free to implement your own logic now. The plugin $this->request object property will let you access Slots/Entities as well as session Attributes/Contexts, while $this->response will let you store additional data to session Attributes/Context and returns your message.
Check Drupal\chatbot_api\IntentRequestInterface and Drupal\chatbot_api\IntentResponseInterface for advance usage.
For Dialogflow, response with custom payload, card or event is supported.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion