A simple C++ class which can handle Alexa requests and responses.
This class is lightly tested and the main purpose is to get more familiar with cpp.
- Port forwarding must be used to have incomming connetions from 443 point to 8080 (Or other configured port) on the server
- Amazon Developer account
- A skill with an endpoint pointing to the server
- It is possible to use noip to create a URL for the skill to use
- eidheim/Simple-Web-Server (Placed in
~/
) - Boost - Used for Asio and property_tree
- Standalone Asio works too
- OpenSSL
With my setup, OpenSSL 1.1.0, boost 1.62.0 and g++-6 are used
See test/example.cpp for basic usage
Alexa::AlexaSkill skill(ApplicationID, path, certificate, privateKey, port);
The above is how one would first initialize the class.
-
Before alexa can connect to the server, the Applicaion ID must be retrieved to filter unwanted requests. This will be put in place of
ApplicationID
. -
path
is the path in the endpoint which is called. For example if the endpoint wasalexa.skill.com
and alexa is callingalexa.skill.com/testingSkill
path
would then betestingSkill
.
Note:
testingSkill
work and/testingSkill
does not. If there is no path leave an empty string.
-
To use a custom endpoint for a skill a self signed certificate must be uploaded for security purposes.
certificate
is the path to this certificate. More information on this can be found here. -
privateKey
is the path to the key created in pair with the certificate above. -
port
is optional. Default it 8080.
TODO: Have
setupServer()
run when callingstart()
skill.setupServer();
This function configures the server and prepares it to start
skill.intents["TestTalking"] = [](std::shared_ptr<Alexa::Request> request, std::shared_ptr<Alexa::Response> response) {
std::cout << "IN TEST TALKING CALLBACK FUNCTION" << std::endl;
response->speech("Talking has been tested");
response->simpleCard("Testing", "Talking has been tested");
};
skill.intents["TestTalking"]
- This will create an item in a map/dictionary
[](std::shared_ptr<Alexa::Request> request, std::shared_ptr<Alexa::Response> response)
- This creates a lambda function with
request
andresponse
as arguments
response->speech("Talking has been tested");
- This takes the
response
argument and calls the functionspeech()
More information on these function will be provided below
response->simpleCard("Testing", "Talking has been tested");
- This takes the
response
argument and calls the functionsimpleCard()
skill.start();
This simply starts the server by joining the server to a thread.
This class is for getting infomation from the request
std::string getAppId();
- Returns the application id used for verification
std::string getType();
- Returns the type of request from amazon (IntentRequest, LaunchRequest, SessionEndedRequest, etc)
More info on requests (Scroll up slightly)
std::string getIntent();
- Gets the name of the intent IF the request is a type
IntentRequest
This is what is used to make alexa respond
These functions will affect how alexa will respond verbally
void speech(std::string s);
- Alexa will attempt to say what is given
std::string s
- A string of what alexa will respond with
void ssml(std::string s);
- Alexa will attpempt to say what is given
std::string s
- A string of what alexa will respond with formatted in SSML
These functions affect the card that can show in the alexa app
void simpleCard(std::string title, std::string content);
- Creates a simple card on the dashboard of the alexa app
std::string title
- The title of the card
std::string content
- The text which will show in the card
void standardCard(std::string title, std::string text, std::string image);
- Creates a standard card on the dashboard of the alexa app
std::string title
- Title of the card
std::string text
- The text displayed in the card
std::string image
- The link to an image to be diplayed on the card
void standardCard(std::string title, std::string text, std::string small, std::string large);
- Creates a standard card on the dashboard of the alexa app
std::string title
- Title of the card
std::string text
- The text displayed in the card
std::string small
- The link to a small image to be diplayed on the card
std::string large
- The link to a large image to be diplayed on the card
Alexa reprompting for a answer
void reprompt(std::string s);
- Makes a reprompt saying when alexa does not understand the user's speech
std::string s
- A string of what alexa will reprompt with
void reprompt(std::string s);
- Makes a reprompt saying when alexa does not understand the user's speech
std::string s
- A string of what alexa will reprompt with formatted in SSML
void shouldEndSession(bool b);
bool b
- Whether to not this response should end the session