Lorna Flerida Espinosa Cuello / 20145845
Dante Faña Badia / 20156079
This document has as purpose to define in big scale all project decision and components, also have the documentation of the project.
- Professor and monitors: to evaluate and get feedbacks from them.
- Peers students: to share knowledge and ideas.
This Project consists of a voice command assistant that will allow you to make online purchases in an online store site based on Shopify.
The Alexa-based device should be a channel for requests to add products to the shopping cart.
- Add product to shopping cart
- Check product price
- Check product availability
- Simulate online purchase checkout
- Define the technology stackÂ
- Define the solution overviewÂ
- Document the reason of the technology selection
Here is technology stack benchmark and selection.
Decision | Alts | Pros | Cons |
---|---|---|---|
Programming language: node |
|
|
|
REST Admin Shopify API |
|
|
|
AWS ASK CLI |
|
|
|
- Create a basic skillÂ
- Documented the skill creation
For the skill creation we're using the Alexa ASK CLI, this tool allows us to create the skill using code first approach, this mean that we don't need to get out of our editor/IDE to build the skill.Â
For test purpose, we only code a simple skill that make Alexa say "hello world".
Before start the creation of this skill, you must have the tools installed and tasks completed following.
- AWS Account
- Amazon Developer Account
- VS Code
- Alexa Skills Kit (ASK) Toolkit
- ASK CLI AWS
Here we open ours skill kit tool that allow us to create, setup, deploy and development.
Here we set up the skill: technology, template and folder.
Here we're waiting to ours CLI create all resources in AWS.
Firs for creating ours skill, we need to change ours invocation world.
Here we check ours skill before the deployment.
Here we're waiting to ours CLI update all resources in AWS and ours skill code.
Using the skill kit to test ours invocation world to open ours skill.
Then we test ours skill, basic intent.
- Integrate Alexa with Shopify API
- Documented Shopify integration
For this integration, we use Shopify Admin API and a rest client to request all the needed endpoint.
Before to start the integration, you must have set up a Shopify dev account.
- AWS Account
- Amazon Developer Account
- Shopify Dev Account
- VS Code
- Alexa Skills Kit (ASK) Toolkit
- ASK CLI AWS
- Shopify Account
Go to https://shopify.dev/ and sign in with your developer account and create a new store, this going to allow you to work with Shopify without any cost.
Go to you store and sign in with you dev account and go home/apps and create a private app, this going to enable the Admin API.
Now copy you API Key and your secret key and let's test the API with CURL.
curl
--location
--request GET 'https://{store-name}.myshopify.com/admin/api/2021-07/products.json?limit=5&fields=id,images, title,variants,tags&since_id='
--header 'Authorization: Basic base64(username:password)'
curl
--location
--request POST 'https://{store-name}.myshopify.com/admin/api/2021-07/orders.json'
--header 'Authorization: Basic base64(username:password)'
--header 'Content-Type: application/json' \
--data-raw '{
"order": {
"line_items": [
{
"variant_id": ${id_product},
"quantity": 1
}
],
"customer": {
"email": "${email}"
}
}
}'
With all the integrations setup and the API testing process to create the Alexa Integrations.
class ShopifyServices{
#client;
constructor(config = shopifyConfig){
const token = Buffer.from(`${config.username}:${config.password}`).toString('base64');
this.#client = axios.create({
baseURL: config.baseUrl,
headers: {
'Authorization': `Basic ${token}`,
'Content-Type': 'application/json'
}
});
}
async getRecommendedProduct({ sinceId = '', limit = 1, fields = 'id,images,title,variants,tags'}){
try {
return (await this.#client.get(`/products.json?limit=${limit}&fields=${fields}&since_id=${sinceId}`)).data.products[0];
} catch(e) {
throw e;
}
}
async placerOrder(order){
try {
const data = JSON.stringify({
order: {
line_items: order.items.map((el) => {
return {
variant_id: el.variantId,
quantity: el.quantity
}
}),
customer: {
email: order.email
}
}
});
return (await this.#client.post('/orders.json', data)).data.order;
} catch(e) {
throw e;
}
}
}
We can use the services that we create to call without problem to Shopify API (line 9).
const ShowProductsIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'ShowProductsIntent';
},
async handle(handlerInput) {
const {attributesManager} = handlerInput;
const attributes = handlerInput.attributesManager.getPersistentAttributes()
const currentProduct = attributes.currentProduct || undefined;
const product = await Shopify.getRecommendedProduct({ sinceId: currentProduct ? currentProduct.id : undefined });
const speakOutput = `This is our recommended product: ${product.title}`;
attributes.currentProduct = product;
handlerInput.attributesManager.setPersistentAttributes(attributes);
handlerInput.attributesManager.savePersistentAttributes();
return handlerInput.responseBuilder
.speak(speakOutput)
.addDelegateDirective({
name: 'AddProductIntent',
confirmationStatus: 'NONE',
slots: {}
})
.getResponse();
}
}
- Demo of the Alexa Skill Working
For this deliverable we present the demo of the skill working.