Last active
April 4, 2019 07:34
-
-
Save armonge/efc0bf25ae7fa4dfddd6865cc5bb1e2e to your computer and use it in GitHub Desktop.
voxa-cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
# set -o xtrace | |
if [ ! -d "$HOME/.ask" ]; then | |
# Create the .ask directory | |
mkdir ~/.ask | |
# Create ASK config | |
sed -e s/ASK_ACCESS_TOKEN/"${ASK_ACCESS_TOKEN}"/g -e \ | |
s/ASK_REFRESH_TOKEN/"${ASK_REFRESH_TOKEN}"/g scripts/ask_cli.json >~/.ask/cli_config | |
fi | |
TMPDIR=$(mktemp -d) | |
cp --recursive "speech-assets/alexa/"* "$TMPDIR" | |
LOCALES=$(ls -l "speech-assets/alexa/" | grep '^d' | awk '{print $9}' | xargs -I% basename %) | |
( | |
cd "$TMPDIR" | |
for LOCALE in "${LOCALES[@]}"; do | |
echo "Updating: $LOCALE" | |
npx ask api update-model --file "$LOCALE/$NODE_ENV-interaction.json" --skill-id "$ALEXA_SKILL_ID" --locale "$LOCALE" | |
done | |
if [[ -n "${ALEXA_LAMBDA_ARN:-}" ]]; then | |
sed -i'' -e s,LAMBDA_ARN,"${ALEXA_LAMBDA_ARN}",g "$NODE_ENV-manifest.json" | |
fi | |
if [[ -n "${ALEXA_SMALL_ICON_URI:-}" ]]; then | |
sed -i'' -e s,SMALL_ICON_URI,"${ALEXA_SMALL_ICON_URI}",g "$NODE_ENV-manifest.json" | |
fi | |
if [[ -n "${ALEXA_LARGE_ICON_URI:-}" ]]; then | |
sed -i'' -e s,LARGE_ICON_URI,"${ALEXA_LARGE_ICON_URI}",g "$NODE_ENV-manifest.json" | |
fi | |
npx ask api update-skill --skill-id "$ALEXA_SKILL_ID" -f "$NODE_ENV-manifest.json" | |
) | |
# Wait 10 seconds and then print the skill status | |
function skillStatus() { | |
local json_response | |
json_response=$(npx ask api get-skill-status --skill-id "$ALEXA_SKILL_ID") | |
echo "$json_response" | grep IN_PROGRESS | |
} | |
i=1 | |
sp="/-\|" | |
echo -n " " | |
while [ -n "$(skillStatus)" ]; do | |
printf "\b${sp:i++%${#sp}:1}" | |
sleep 1 | |
printf "\b${sp:i++%${#sp}:1}" | |
sleep 1 | |
printf "\b${sp:i++%${#sp}:1}" | |
sleep 1 | |
printf "\b${sp:i++%${#sp}:1}" | |
done | |
echo -en "\b" | |
npx ask api get-skill-status --skill-id "$ALEXA_SKILL_ID" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
set -o xtrace | |
if [ ! -f "dialogflow_key.json" ] && [ "${DIALOGFLOW_KEY:-}" ]; then | |
echo "$DIALOGFLOW_KEY" >dialogflow_key.json | |
fi | |
if [ -f "dialogflow_key.json" ]; then | |
gcloud auth activate-service-account --key-file=dialogflow_key.json | |
fi | |
TMPDIR=$(mktemp -d) | |
cp --recursive "speech-assets/dialogflow/$NODE_ENV" "$TMPDIR" | |
cd "$TMPDIR/$NODE_ENV" | |
if [[ -n "${DIALOGFLOW_WEBHOOK_URL:-}" ]]; then | |
sed -i'' -e s,WEBHOOK_URL,"${DIALOGFLOW_WEBHOOK_URL}",g "agent.json" | |
fi | |
if [[ -n "${DIALOGFLOW_API_KEY_VALUE:-}" ]]; then | |
sed -i'' -e s,WEBHOOK_API_KEY_VALUE,"${DIALOGFLOW_API_KEY_VALUE}",g "agent.json" | |
fi | |
zip --recurse-paths "deploy.zip" "./" | |
AGENT_CONTENT="$(base64 -w 0 "deploy.zip")" | |
AUTHORIZATION=$(gcloud auth print-access-token) | |
cat <<EOF >CURL_PAYLOAD.json | |
{"agentContent": "$AGENT_CONTENT"} | |
EOF | |
curl "https://dialogflow.googleapis.com/v2beta1/projects/$DIALOGFLOW_PROJECT_ID/agent:restore" \ | |
-X POST \ | |
-H "Authorization: Bearer $AUTHORIZATION" \ | |
-H "Accept: application/json" \ | |
-H "Content-Type: application/json" \ | |
--compressed \ | |
--data-binary @CURL_PAYLOAD.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
set -o xtrace | |
IFS=$'\n\t' | |
npx sls deploy --stage "$NODE_ENV" | |
npx gulp s3 | |
ASSETS_BUCKET_DOMAIN=$(npx sls info --stage "$NODE_ENV" --verbose | grep AssetsBucketDomain | awk '{print $2}') | |
if [[ -n "${DIALOGFLOW_PROJECT_ID:-}" ]]; then | |
API_KEY_NAME="$NODE_ENV-$SERVICE_NAME-auth" | |
DIALOGFLOW_WEBHOOK_URL=$(npx sls info --stage "$NODE_ENV" --verbose | grep POST | grep googleAssistant | awk '{print $3}') | |
DIALOGFLOW_API_KEY_VALUE=$(npx sls info --stage "$NODE_ENV" --verbose | grep "$API_KEY_NAME" | awk '{print $2}') | |
export DIALOGFLOW_WEBHOOK_URL | |
export DIALOGFLOW_API_KEY_VALUE | |
./scripts/deploy-dialogflow.sh | |
fi | |
if [[ -n "${ALEXA_SKILL_ID:-}" ]]; then | |
ALEXA_LAMBDA_ARN=$(npx sls info --stage "$NODE_ENV" --verbose | grep AlexaLambdaFunctionQualifiedArn | awk '{print $2}' | sed 's/..$//') | |
ALEXA_SMALL_ICON_URI="https://${ASSETS_BUCKET_DOMAIN}/images/APP_ICON.png" | |
ALEXA_LARGE_ICON_URI="https://${ASSETS_BUCKET_DOMAIN}/images/APP_ICON_LARGE.png" | |
export ALEXA_LAMBDA_ARN | |
export ALEXA_LARGE_ICON_URI | |
export ALEXA_SMALL_ICON_URI | |
./scripts/deploy-alexa.sh | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Welcome to Serverless! | |
# | |
# For full config options, check the docs: | |
# docs.serverless.com | |
# | |
# Happy Coding! | |
service: ${self:custom.config.service} | |
plugins: | |
- serverless-plugin-typescript | |
custom: | |
config: ${file(src/config/index.js):asFunction} | |
DynamoDBBillingMode: | |
production: PAY_PER_REQUEST | |
staging: PROVISIONED | |
DynamoDBCapacity: | |
production: !Ref AWS::NoValue | |
staging: | |
ReadCapacityUnits: 5 | |
WriteCapacityUnits: 5 | |
provider: | |
name: aws | |
runtime: nodejs8.10 | |
apiKeys: # List of API keys to be used by your service API Gateway REST API | |
- ${env:NODE_ENV}-${self:service}-auth | |
# Optional service wide function tags | |
tags: | |
Environment: ${env:NODE_ENV} | |
Service: ${self:service} | |
environment: | |
NODE_ENV: ${env:NODE_ENV} | |
S3_BUCKET: !Ref assets | |
DYNAMODB_USERS_TABLE: !Ref TableUsers | |
SERVICE_NAME: ${self:service} | |
DEBUG: voxa | |
iamRoleStatements: | |
- Effect: "Allow" | |
Action: | |
- "dynamodb:*" | |
Resource: !GetAtt TableUsers.Arn | |
functions: | |
googleAssistant: | |
timeout: 6 | |
handler: src/handler.assistantHandler | |
memorySize: 512 | |
events: | |
- http: | |
path: googleAssistant | |
method: POST | |
private: true # Requires clients to add API keys values in the `x-api-key` header of their request | |
alexa: | |
timeout: 6 | |
handler: src/handler.alexaHandler | |
memorySize: 512 | |
events: | |
- alexaSkill: ${env:ALEXA_SKILL_ID} | |
package: | |
include: | |
- src/**/*.xml | |
- src/**/*.json | |
- content/**/*.json | |
resources: | |
Resources: | |
assets: | |
Type: AWS::S3::Bucket | |
Properties: | |
BucketName: ${self:custom.config.s3.bucket} | |
AccessControl: PublicRead | |
CorsConfiguration: | |
CorsRules: | |
- AllowedOrigins: | |
- "*" | |
AllowedMethods: | |
- GET | |
TableUsers: | |
Type: AWS::DynamoDB::Table | |
Properties: | |
TableName: ${self:custom.config.dynamodb.tables.users} | |
BillingMode: ${self:custom.DynamoDBBillingMode.${env:NODE_ENV}} | |
ProvisionedThroughput: ${self:custom.DynamoDBCapacity.${env:NODE_ENV}} | |
AttributeDefinitions: | |
- AttributeName: userId | |
AttributeType: S | |
KeySchema: | |
- AttributeName: userId | |
KeyType: HASH | |
Outputs: | |
AssetsBucketDomain: | |
Description: The bucket Domain | |
Value: !GetAtt assets.DomainName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment