Skip to content

Commit 896cd09

Browse files
author
Abdulhakim Ajetunmobi
committed
add capabilities scripting support
1 parent a2941c9 commit 896cd09

File tree

7 files changed

+79
-39
lines changed

7 files changed

+79
-39
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const VONAGE_API_KEY = process.env.VONAGE_API_KEY;
2+
const VONAGE_API_SECRET = process.env.VONAGE_API_SECRET;
3+
const VONAGE_APPLICATION = process.env.VONAGE_APPLICATION_ID || '8b6851fe-567c-4e86-adf8-3bea83633c60';
4+
5+
const capabilities = [<CAPABILITIES>];
6+
7+
if (capabilities) {
8+
console.log(`Enabling ${capabilities}`);
9+
10+
// Fetch the application JSON
11+
const response = await fetch(`https://api.nexmo.com/v2/applications/${VONAGE_APPLICATION}`, {
12+
method: 'GET',
13+
headers: {
14+
'Content-Type': 'application/json',
15+
'Authorization': `Basic ${Buffer.from(`${VONAGE_API_KEY}:${VONAGE_API_SECRET}`).toString('base64')}`
16+
}
17+
});
18+
19+
const data = await response.json();
20+
21+
// Ensure the capabilities object exists and update it
22+
23+
const capabilitiesObject = {};
24+
capabilities.forEach(capability => {
25+
if (capability === "voice") {
26+
capabilitiesObject.voice = {};
27+
}
28+
});
29+
30+
const updatedData = {
31+
...data,
32+
capabilities: capabilitiesObject
33+
};
34+
35+
// Send the updated JSON back
36+
const updateResponse = await fetch(`https://api.nexmo.com/v2/applications/${VONAGE_APPLICATION}`, {
37+
method: 'PUT',
38+
headers: {
39+
'Content-Type': 'application/json',
40+
'Authorization': `Basic ${Buffer.from(`${VONAGE_API_KEY}:${VONAGE_API_SECRET}`).toString('base64')}`
41+
},
42+
body: JSON.stringify(updatedData)
43+
});
44+
45+
if (updateResponse.ok) {
46+
console.log('Successfully updated the application.');
47+
} else {
48+
console.error('Failed to update the application.');
49+
}
50+
} else {
51+
console.log('No Capabilities, skipping.');
52+
}

scripting/TemplateWorkspace/.vscode/tasks.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@
4343
"close": true
4444
}
4545
},
46+
{
47+
"label": "EnableCapabilities",
48+
"type": "shell",
49+
"command": "chmod +x ./.vscode/capabilities.sh; ./.vscode/capabilities.sh",
50+
"presentation": {
51+
"reveal": "never",
52+
"close": true
53+
}
54+
},
4655
{
4756
"label": "CleanUp",
4857
"type": "shell",

scripting/createWorkspace.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fi
1919
SLUG=$(jq -r '.slug' "$CONFIG_FILE")
2020
VERSION=$(jq -r '.version' "$CONFIG_FILE")
2121
FILES=$(jq -r '.files[]' "$CONFIG_FILE")
22+
CAPABILITIES=$(jq -r '.capabilities[]' "$CONFIG_FILE")
2223
PANELS=$(jq -r '.panels[]' "$CONFIG_FILE")
2324

2425
# Create files from the "files" array
@@ -53,11 +54,21 @@ else
5354
echo "$OFOS_FILE not found."
5455
fi
5556

57+
# Update capabilities.sh using a temporary file
58+
CAPABILITIES_FILE=".vscode/capabilities.js"
59+
if [ -f "$CAPABILITIES_FILE" ]; then
60+
TEMP_FILE=$(mktemp)
61+
sed "s|<CAPABILITIES>|$CAPABILITIES|" "$CAPABILITIES_FILE" > "$TEMP_FILE" && mv "$TEMP_FILE" "$CAPABILITIES_FILE"
62+
echo "Updated $CAPABILITIES_FILE with: $CAPABILITIES"
63+
else
64+
echo "$CAPABILITIES_FILE not found."
65+
fi
66+
5667
# Update tasks.json using a temporary file
5768
if echo "${PANELS[@]}" | grep -q "browser"; then
58-
TASKS='["ExportEnv", "OpenContentView", "ConfigurePreview", "OpenTerminal", "CleanUp", "OpenPreviewView"]'
69+
TASKS='["ExportEnv", "OpenContentView", "ConfigurePreview", "OpenTerminal", "EnableCapabilities", "CleanUp", "OpenPreviewView"]'
5970
else
60-
TASKS='["ExportEnv", "OpenContentView", "OpenTerminal", "CleanUp"]'
71+
TASKS='["ExportEnv", "OpenContentView", "OpenTerminal", "EnableCapabilities", "CleanUp"]'
6172
fi
6273

6374
TASKS_FILE=".vscode/tasks.json"

tutorials/voice_api-node-outbound/src/content/docs/05-enable-voice.md

Lines changed: 0 additions & 34 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"files": [
3-
"make-call.js",
4-
"enable-voice.js"
3+
"make-call.js"
54
],
65
"panels": [
76
"terminal"
87
],
9-
"version": "0.2.0"
8+
"capabilities": [
9+
"voice"
10+
],
11+
"version": "0.3.0"
1012
}

0 commit comments

Comments
 (0)