Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/docs/building/template-utilities/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ If the value is not found in the environment variables, the `scripts/config/mapp
```json title=mappings.json
{
"VARIABLE_NAME_HERE": {
"type": "tr-workflow", // Type of Twilio resource to fetch the value of: serverless-domain, serverless-service, serverless-environment, serverless-function, tr-workspace, tr-workflow, chat-service, or sync-service
"type": "tr-workflow", // Type of Twilio resource to fetch the value of: serverless-domain, serverless-service, serverless-environment, serverless-function, studio-flow, tr-queue, tr-workspace, tr-workflow, chat-service, or sync-service
"name": "My Workflow", // Name of resource to find
"localValue": "My Other Workflow", // Optionally override the name property with a different one when running locally
"fallback": "/(Assign.*Anyone)/", // Optionally define a fallback in case the defined name is not found. Note that this regex format is allowed in any of these properties except 'type'.
"parent": "PARENT_VARIABLE_NAME_HERE" // Required for serverless-environment, serverless-function, and tr-workflow types. Indicates the variable representing this item's parent object (of type serverless-service or tr-workspace, depending on this item's type).
"parent": "PARENT_VARIABLE_NAME_HERE" // Required for serverless-environment, serverless-function, tr-queue, and tr-workflow types. Indicates the variable representing this item's parent object (of type serverless-service or tr-workspace, depending on this item's type).
}
}
```
Expand Down
23 changes: 23 additions & 0 deletions scripts/common/fetch-cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,29 @@ export const fetchServerlessFunctions = (serviceSid) => {
}, serviceSid);
}

export const fetchStudioFlows = () => {
fetchResources("studio-flow", "Studio flows", "api:studio:v2:flows:list", (fetched, wanted, wantedResources) => {
if (isMatch(wantedResources[wanted].name, fetched.friendlyName, false)) {
resultCache[wanted] = fetched.sid;
return true;
}
});
}

export const fetchTrQueues = (workspaceSid) => {
if (!workspaceSid) {
console.warn("TaskRouter workspace SID missing; unable to fetch task queues");
return;
}
fetchResources(`tr-queue`, `TaskRouter task queues`, `api:taskrouter:v1:workspaces:task-queues:list --workspace-sid=${workspaceSid}`, (fetched, wanted, wantedResources) => {
// only match the fallback if the specified name is not already found
if (isMatch(wantedResources[wanted].name, fetched.friendlyName, true) || (!resultCache[wanted] && isMatch(wantedResources[wanted].fallback, fetched.friendlyName, true))) {
resultCache[wanted] = fetched.sid;
return true;
}
}, workspaceSid);
}

export const fetchTrWorkflows = (workspaceSid) => {
if (!workspaceSid) {
console.warn("TaskRouter workspace SID missing; unable to fetch workflows");
Expand Down
8 changes: 7 additions & 1 deletion scripts/common/fill-replacements.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as fetchCli from "./fetch-cli.mjs";

const parseData = (data) => {
let result = {};
for (const match of data.matchAll(new RegExp(`<${placeholderPrefix}_(.*)>`, 'g'))) {
for (const match of data.matchAll(new RegExp(`<${placeholderPrefix}_([^>\n\r]*)>`, 'g'))) {
result[match[1]] = match[0];
}
return result;
Expand Down Expand Up @@ -95,6 +95,12 @@ const fillVar = (key, envVars, environment) => {
case "serverless-function":
fetchCli.fetchServerlessFunctions(envVars[parentKey]);
break;
case "studio-flow":
fetchCli.fetchStudioFlows();
break;
case "tr-queue":
fetchCli.fetchTrQueues(envVars[parentKey]);
break;
case "tr-workspace":
fetchCli.fetchTrWorkspaces();
break;
Expand Down