diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 92411a7..3b6fc33 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -18,7 +18,7 @@ jobs: - name: Get changed files id: get-changed-files - uses: tj-actions/changed-files@2f7c5bf + uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 - name: Get changed folder id: get-changed-folder diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index 41bb0dc..637300b 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -17,7 +17,7 @@ jobs: - name: Get changed files id: get-changed-files - uses: tj-actions/changed-files@2f7c5bf + uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 - name: Get changed folder id: get-changed-folder diff --git a/scripting/TemplateWorkspace/.vscode/capabilities.js b/scripting/TemplateWorkspace/.vscode/capabilities.js new file mode 100644 index 0000000..bf9c7fe --- /dev/null +++ b/scripting/TemplateWorkspace/.vscode/capabilities.js @@ -0,0 +1,52 @@ +const VONAGE_API_KEY = process.env.VONAGE_API_KEY; +const VONAGE_API_SECRET = process.env.VONAGE_API_SECRET; +const VONAGE_APPLICATION = process.env.VONAGE_APPLICATION_ID || '8b6851fe-567c-4e86-adf8-3bea83633c60'; + +const capabilities = []; + +if (capabilities) { + console.log(`Enabling ${capabilities}`); + + // Fetch the application JSON + const response = await fetch(`https://api.nexmo.com/v2/applications/${VONAGE_APPLICATION}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Basic ${Buffer.from(`${VONAGE_API_KEY}:${VONAGE_API_SECRET}`).toString('base64')}` + } + }); + + const data = await response.json(); + + // Ensure the capabilities object exists and update it + + const capabilitiesObject = {}; + capabilities.forEach(capability => { + if (capability === "voice") { + capabilitiesObject.voice = {}; + } + }); + + const updatedData = { + ...data, + capabilities: capabilitiesObject + }; + + // Send the updated JSON back + const updateResponse = await fetch(`https://api.nexmo.com/v2/applications/${VONAGE_APPLICATION}`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Basic ${Buffer.from(`${VONAGE_API_KEY}:${VONAGE_API_SECRET}`).toString('base64')}` + }, + body: JSON.stringify(updatedData) + }); + + if (updateResponse.ok) { + console.log('Successfully updated the application.'); + } else { + console.error('Failed to update the application.'); + } +} else { + console.log('No Capabilities, skipping.'); +} diff --git a/scripting/TemplateWorkspace/.vscode/tasks.json b/scripting/TemplateWorkspace/.vscode/tasks.json index de1aea5..156f2e3 100644 --- a/scripting/TemplateWorkspace/.vscode/tasks.json +++ b/scripting/TemplateWorkspace/.vscode/tasks.json @@ -43,6 +43,15 @@ "close": true } }, + { + "label": "EnableCapabilities", + "type": "shell", + "command": "chmod +x ./.vscode/capabilities.sh; ./.vscode/capabilities.sh", + "presentation": { + "reveal": "never", + "close": true + } + }, { "label": "CleanUp", "type": "shell", diff --git a/scripting/createWorkspace.sh b/scripting/createWorkspace.sh index 6acf3f1..83ee145 100755 --- a/scripting/createWorkspace.sh +++ b/scripting/createWorkspace.sh @@ -19,6 +19,7 @@ fi SLUG=$(jq -r '.slug' "$CONFIG_FILE") VERSION=$(jq -r '.version' "$CONFIG_FILE") FILES=$(jq -r '.files[]' "$CONFIG_FILE") +CAPABILITIES=$(jq -r '.capabilities[]' "$CONFIG_FILE") PANELS=$(jq -r '.panels[]' "$CONFIG_FILE") # Create files from the "files" array @@ -53,11 +54,21 @@ else echo "$OFOS_FILE not found." fi +# Update capabilities.sh using a temporary file +CAPABILITIES_FILE=".vscode/capabilities.js" +if [ -f "$CAPABILITIES_FILE" ]; then + TEMP_FILE=$(mktemp) + sed "s||$CAPABILITIES|" "$CAPABILITIES_FILE" > "$TEMP_FILE" && mv "$TEMP_FILE" "$CAPABILITIES_FILE" + echo "Updated $CAPABILITIES_FILE with: $CAPABILITIES" +else + echo "$CAPABILITIES_FILE not found." +fi + # Update tasks.json using a temporary file if echo "${PANELS[@]}" | grep -q "browser"; then - TASKS='["ExportEnv", "OpenContentView", "ConfigurePreview", "OpenTerminal", "CleanUp", "OpenPreviewView"]' + TASKS='["ExportEnv", "OpenContentView", "ConfigurePreview", "OpenTerminal", "EnableCapabilities", "CleanUp", "OpenPreviewView"]' else - TASKS='["ExportEnv", "OpenContentView", "OpenTerminal", "CleanUp"]' + TASKS='["ExportEnv", "OpenContentView", "OpenTerminal", "EnableCapabilities", "CleanUp"]' fi TASKS_FILE=".vscode/tasks.json" diff --git a/tutorials/voice_api-node-outbound/src/content/docs/05-enable-voice.md b/tutorials/voice_api-node-outbound/src/content/docs/05-enable-voice.md deleted file mode 100644 index 3352186..0000000 --- a/tutorials/voice_api-node-outbound/src/content/docs/05-enable-voice.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -title: Enable Voice ---- - -To make a call, you need to enable the voice capability on your Vonage application. Copy this code into the `enable-voice.js` file: - -```js -const { Vonage } = require('@vonage/server-sdk'); - -const vonage = new Vonage({ - apiKey: process.env.VONAGE_API_KEY, - apiSecret: process.env.VONAGE_API_SECRET, - applicationId: process.env.VONAGE_APPLICATION_ID, - privateKey: process.env.VONAGE_PRIVATE_KEY, -}); - -vonage.applications.getApplication(process.env.VONAGE_APPLICATION_ID) - .then((app) => { - app.capabilities = { - voice: {} - } - vonage.applications.updateApplication(app) - .then(() => console.log("App Updated")) - .catch((error) => console.dir(error)); - }) - .catch((error) => console.error(error)); -``` - -Then run this command in the Terminal: - -```sh -node enable-voice.js -``` - diff --git a/tutorials/voice_api-node-outbound/src/content/docs/06-run-code.md b/tutorials/voice_api-node-outbound/src/content/docs/05-run-code.md similarity index 100% rename from tutorials/voice_api-node-outbound/src/content/docs/06-run-code.md rename to tutorials/voice_api-node-outbound/src/content/docs/05-run-code.md diff --git a/tutorials/voice_api-node-outbound/src/content/docs/07-whats-next.md b/tutorials/voice_api-node-outbound/src/content/docs/06-whats-next.md similarity index 100% rename from tutorials/voice_api-node-outbound/src/content/docs/07-whats-next.md rename to tutorials/voice_api-node-outbound/src/content/docs/06-whats-next.md diff --git a/tutorials/voice_api-node-outbound/tutorial-config.json b/tutorials/voice_api-node-outbound/tutorial-config.json index 546ec3b..81cafd5 100644 --- a/tutorials/voice_api-node-outbound/tutorial-config.json +++ b/tutorials/voice_api-node-outbound/tutorial-config.json @@ -1,10 +1,12 @@ { "files": [ - "make-call.js", - "enable-voice.js" + "make-call.js" ], "panels": [ "terminal" ], - "version": "0.2.0" + "capabilities": [ + "voice" + ], + "version": "0.3.0" } \ No newline at end of file