Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4266471

Browse files
Merge pull request #1 from restackio/twilio
Twilio example Former-commit-id: 01b5da1 Former-commit-id: e29dd4118939155f90ef58cf4bcfb98283e75bd0
2 parents ad479ea + b532afc commit 4266471

33 files changed

+4189
-14
lines changed

examples/hello/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"start.watch": "nodemon src/run.ts",
7+
"start.watch": "nodemon src/pods.ts",
88
"dev": "pnpm start.watch",
99
"workflow": "ts-node ./scheduleWorkflow.ts",
1010
"test": "echo \"Error: no test specified\" && exit 1"
@@ -23,7 +23,7 @@
2323
"@temporalio/workflow": "^1.10.3",
2424
"dotenv": "^16.4.5",
2525
"openai": "^4.53.2",
26-
"@restackio/restack-sdk-ts": "0.0.7",
26+
"@restackio/restack-sdk-ts": "^0.0.33",
2727
"zod": "^3.23.8",
2828
"zod-to-json-schema": "^3.23.1"
2929
},

examples/hello/pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/hello/scheduleWorkflow.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ async function scheduleWorkflow() {
44
try {
55
const restack = new Restack();
66

7-
const handle = await restack.schedule({
7+
const workflowId = `${Date.now()}-exampleWorkflow`;
8+
const runId = await restack.schedule({
89
workflowName: "example",
910
workflowId: `${Date.now()}-exampleWorkflow`,
1011
input: [
@@ -14,11 +15,9 @@ async function scheduleWorkflow() {
1415
],
1516
});
1617

17-
console.log("Workflow scheduled successfully:", handle.firstExecutionRunId);
18+
const result = await restack.getResult(workflowId, runId);
1819

19-
handle.result().then((result) => {
20-
console.log("Workflow result:", result);
21-
});
20+
console.log("Workflow result:", result);
2221

2322
process.exit(0); // Exit the process successfully
2423
} catch (error) {

examples/hello/src/functions/openai/chat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ZodObject } from "zod";
2-
import { FunctionFailure, log } from "@restackio/restack-sdk-ts/dist/function";
2+
import { FunctionFailure, log } from "@restackio/restack-sdk-ts/function";
33
import { zodPrompt } from "./zodPrompt";
44
import { openaiClient } from "./client";
55
import { openaiCost } from "./cost";
File renamed without changes.

examples/hello/src/workflows/example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { log, step } from "@restackio/restack-sdk-ts/dist/workflow";
1+
import { log, step } from "@restackio/restack-sdk-ts/workflow";
22
import * as functions from "../functions";
33
import { UsageOutput } from "../functions/openai/chat";
44

examples/twilio/.env.example

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
TWILIO_ACCOUNT_SID=
3+
TWILIO_AUTH_TOKEN=
4+
FROM_NUMBER=
5+
APP_NUMBER=
6+
YOUR_NUMBER=
7+
8+
# Your ngrok or server URL
9+
SERVER=5756-5-61-150-161.ngrok-free.app
10+
11+
# Service API Keys
12+
OPENAI_API_KEY=
13+
DEEPGRAM_API_KEY=
14+
# XI_API_KEY=
15+
# XI_MODEL_ID=eleven_turbo_v2_5
16+
17+
# Deepgram voice model, see more options here: https://developers.deepgram.com/docs/tts-models
18+
VOICE_MODEL=aura-asteria-en

examples/twilio/callWorkflow.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Restack from "@restackio/restack-sdk-ts";
2+
3+
async function scheduleWorkflow() {
4+
try {
5+
const restack = new Restack();
6+
7+
const workflowRunId = await restack.schedule({
8+
workflowName: "twilioCallWorkflow",
9+
workflowId: `${Date.now()}-twilioCallWorkflow`,
10+
});
11+
12+
console.log("Workflow scheduled successfully:", workflowRunId);
13+
14+
process.exit(0); // Exit the process successfully
15+
} catch (error) {
16+
console.error("Error scheduling workflow:", error);
17+
process.exit(1); // Exit the process with an error code
18+
}
19+
}
20+
21+
scheduleWorkflow();

examples/twilio/package.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "restack-twilio",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"dev-server": "ts-node-dev --respawn --transpile-only src/server.ts",
8+
"dev-pods": "ts-node-dev --respawn --transpile-only src/pods.ts",
9+
"call": "ts-node ./callWorkflow.ts",
10+
"ngrok": "ngrok http 4000"
11+
},
12+
"keywords": [],
13+
"author": "",
14+
"license": "ISC",
15+
"dependencies": {
16+
"@deepgram/sdk": "^3.5.0",
17+
"@restackio/restack-sdk-ts": "^0.0.33",
18+
"@temporalio/workflow": "^1.10.3",
19+
"axios": "^1.7.3",
20+
"cors": "^2.8.5",
21+
"dotenv": "^16.4.5",
22+
"express": "^4.19.2",
23+
"openai": "^4.54.0",
24+
"twilio": "^5.2.2",
25+
"typescript": "^5.5.4",
26+
"uuid": "^10.0.0",
27+
"ws": "^8.18.0"
28+
},
29+
"devDependencies": {
30+
"@types/cors": "^2.8.17",
31+
"@types/express": "^4.17.21",
32+
"@types/node": "^22.1.0",
33+
"@types/uuid": "^10.0.0",
34+
"@types/ws": "^8.5.12",
35+
"nodemon": "^3.1.4",
36+
"ts-node": "^10.9.2",
37+
"ts-node-dev": "^2.0.0"
38+
},
39+
"optionalDependencies": {
40+
"bufferutil": "^4.0.8"
41+
}
42+
}

0 commit comments

Comments
 (0)