\Patami\IPS\Services\Alexa\Skills\CustomIOModuleTrait

Provides common methods for Amazon Alexa Custom Skill I/O modules.

Eliminates the need for a common base class, since both WebHook and WebOAuth I/Os are being used.

Summary

Methods
Properties
Constants
GetLaunchIntentClassName()
GetIntentClassNames()
ReadIntentProperty()
GetLastResponse()
No public properties found
No constants found
CustomSkillCreate()
GetCustomSkillConfigurationFormData()
GetLocaleLabel()
GetRequestClassName()
CreateExceptionResponse()
ProcessRequest()
GetTranslatedPropertyName()
SendResponse()
GetLastResponseSemaphoreName()
GetLastResponseSemaphoreTimeout()
GetLastResponseBufferName()
SetLastResponse()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

GetLaunchIntentClassName()

GetLaunchIntentClassName() : string

Returns the FQCN of the intent class used for LaunchRequests.

For WebHook requests, the user can override the LaunchRequest with an Intent Module instance.

Returns

string —

FQCN of the intent class.

GetIntentClassNames()

GetIntentClassNames() : array

Returns a list of FQCNs of the intent classes used to IntentRequests.

For WebHook requests, the user can override them or add new intents with Intent Module instances.

Returns

array —

FQCNs of the intent classes.

ReadIntentProperty()

ReadIntentProperty(\Patami\IPS\Services\Alexa\Skills\Custom\ModuleIntent  $intent, string  $name) : mixed

Returns the value of an intent property.

This method is called by the intent object embedded in the configuration form,

Parameters

\Patami\IPS\Services\Alexa\Skills\Custom\ModuleIntent $intent

Intent object.

string $name

Name of the intent configuration property.

Returns

mixed —

Value of the property.

GetLastResponse()

GetLastResponse() : \Patami\IPS\IO\ResponseInterface

Returns the last response sent to the Amazon servers from the IPS object buffer.

Throws

\Patami\IPS\Services\Alexa\Skills\Custom\Exceptions\LastResponseNotFoundException

if no last response was stored in the IPS object buffer.

Returns

\Patami\IPS\IO\ResponseInterface

Last response object.

CustomSkillCreate()

CustomSkillCreate() 

Registers configuration properties for Alexa Custom Skill I/O modules required by the intents of skill.

Called by WebHookIOModule::Create() or WebOAuthIOModule::Create(). Calls the SkillCreate() method of the included IOModuleTrait, which calls the IOModule::Create() method.

Throws

\Patami\IPS\Services\Alexa\Skills\Custom\Exceptions\InvalidIntentConfigurationPropertyException

if the type of an intent configuration property is invalid.

GetCustomSkillConfigurationFormData()

GetCustomSkillConfigurationFormData() : array

Adds sections specified by the intents of an Alexa Custom Skill I/O module to its configuration page.

Called by WebHookIOModule::GetConfigurationFormData() or WebOAuthIOModule::GetConfigurationFormData(). Calls the GetSkillConfigurationFormData() method of the included IOModuleTrait, which calls the IOModule::GetConfigurationFormData() method.

Returns

array —

IPS module configuration form data.

GetLocaleLabel()

GetLocaleLabel() : string

Returns the label of the default locale configuration field.

Returns

string —

Translated label of the configuration field.

GetRequestClassName()

GetRequestClassName() : string

Returns the FQCN of the request class.

This needs to be overridden by the concrete Custom Skill I/O class to use the matching request class.

Returns

string —

FQCN of the request class.

CreateExceptionResponse()

CreateExceptionResponse(\Exception  $e, string  $locale) : \Patami\IPS\Services\Alexa\Skills\Custom\TellResponse

Returns an Alexa response object with the translated text from the given exception.

Parameters

\Exception $e

Throws exception from which the exception message should be retrieved.

string $locale

Locale code used for the translation of the message.

Returns

\Patami\IPS\Services\Alexa\Skills\Custom\TellResponse

Response object to be returned to the Amazon servers.

ProcessRequest()

ProcessRequest(string  $text) : \Patami\IPS\Services\Alexa\Skills\Custom\Response

Creates a new request object from the supplied request text, processes the request and returns the response.

If an exception occurs while processing the request, if is caught and Alexa will speak the exception message.

Parameters

string $text

JSON-encoded request body received from the Amazon servers.

Throws

\Patami\IPS\Services\Alexa\Skills\Custom\Exceptions\InvalidIntentResponseException

if the Request::Process() method did not return a Response object.

Returns

\Patami\IPS\Services\Alexa\Skills\Custom\Response

Response object to be sent back to the Amazon servers.

GetTranslatedPropertyName()

GetTranslatedPropertyName(string  $className, string  $name) : string

Returns a translated configuration form property name.

This is used to make sure the properties required by the built-in intents have unique names by prefixing the property name with the FQCN of the intent class.

Parameters

string $className

FQCN of the intent class.

string $name

Name of the property.

Returns

string —

Translated property name.

SendResponse()

SendResponse(\Patami\IPS\IO\ResponseInterface  $response) 

Saves the response on the IPS object buffer and calls the parent method to send the response to the Amazon servers.

This is required to allow the AMAZON.RepeatIntent intent to speak the last response again.

Parameters

\Patami\IPS\IO\ResponseInterface $response

Response to be sent to the Amazon servers.

GetLastResponseSemaphoreName()

GetLastResponseSemaphoreName() : string

Returns the name of the semaphore used to make sure the IPS object buffer is locked for exclusive access.

Returns

string —

Name of the semaphore.

GetLastResponseSemaphoreTimeout()

GetLastResponseSemaphoreTimeout() : integer

Returns the number of milliseconds to wait for exclusive access to the IPS object buffer.

Returns

integer —

Milliseconds to wait for semaphore timeout.

GetLastResponseBufferName()

GetLastResponseBufferName() : string

Returns the name of the IPS object buffer used to store the last response.

Returns

string —

Name of the IPS object buffer.

SetLastResponse()

SetLastResponse(\Patami\IPS\IO\ResponseInterface  $response) : boolean

Remembers the response sent to the Amazon servers in the IPS object buffer.

Parameters

\Patami\IPS\IO\ResponseInterface $response

Last response object.

Returns

boolean