Skip to content

Instantly share code, notes, and snippets.

@armonge
Last active August 27, 2019 06:14
Show Gist options
  • Save armonge/d475590cbb95d3856c13052c9aef1c2b to your computer and use it in GitHub Desktop.
Save armonge/d475590cbb95d3856c13052c9aef1c2b to your computer and use it in GitHub Desktop.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment