@divyacon/piece-twilio 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.MIT-AP +24 -0
- package/README.md +8 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/action/download-recording-media.d.ts +6 -0
- package/dist/lib/action/download-recording-media.d.ts.map +1 -0
- package/dist/lib/action/download-recording-media.js +77 -0
- package/dist/lib/action/download-recording-media.js.map +1 -0
- package/dist/lib/action/get-message.d.ts +4 -0
- package/dist/lib/action/get-message.d.ts.map +1 -0
- package/dist/lib/action/get-message.js +36 -0
- package/dist/lib/action/get-message.js.map +1 -0
- package/dist/lib/action/make-call.d.ts +10 -0
- package/dist/lib/action/make-call.d.ts.map +1 -0
- package/dist/lib/action/make-call.js +98 -0
- package/dist/lib/action/make-call.js.map +1 -0
- package/dist/lib/action/phone-number-lookup.d.ts +4 -0
- package/dist/lib/action/phone-number-lookup.d.ts.map +1 -0
- package/dist/lib/action/phone-number-lookup.js +44 -0
- package/dist/lib/action/phone-number-lookup.js.map +1 -0
- package/dist/lib/action/send-sms.d.ts +6 -0
- package/dist/lib/action/send-sms.d.ts.map +1 -0
- package/dist/lib/action/send-sms.js +44 -0
- package/dist/lib/action/send-sms.js.map +1 -0
- package/dist/lib/common/index.d.ts +9 -0
- package/dist/lib/common/index.d.ts.map +1 -0
- package/dist/lib/common/index.js +56 -0
- package/dist/lib/common/index.js.map +1 -0
- package/dist/lib/trigger/new-call.d.ts +3 -0
- package/dist/lib/trigger/new-call.d.ts.map +1 -0
- package/dist/lib/trigger/new-call.js +135 -0
- package/dist/lib/trigger/new-call.js.map +1 -0
- package/dist/lib/trigger/new-incoming-sms.d.ts +11 -0
- package/dist/lib/trigger/new-incoming-sms.d.ts.map +1 -0
- package/dist/lib/trigger/new-incoming-sms.js +108 -0
- package/dist/lib/trigger/new-incoming-sms.js.map +1 -0
- package/dist/lib/trigger/new-phone-number.d.ts +3 -0
- package/dist/lib/trigger/new-phone-number.d.ts.map +1 -0
- package/dist/lib/trigger/new-phone-number.js +113 -0
- package/dist/lib/trigger/new-phone-number.js.map +1 -0
- package/dist/lib/trigger/new-recording.d.ts +3 -0
- package/dist/lib/trigger/new-recording.d.ts.map +1 -0
- package/dist/lib/trigger/new-recording.js +123 -0
- package/dist/lib/trigger/new-recording.js.map +1 -0
- package/dist/lib/trigger/new-transcription.d.ts +3 -0
- package/dist/lib/trigger/new-transcription.d.ts.map +1 -0
- package/dist/lib/trigger/new-transcription.js +112 -0
- package/dist/lib/trigger/new-transcription.js.map +1 -0
- package/package.json +43 -3
- package/src/index.ts +63 -0
- package/src/lib/action/download-recording-media.ts +74 -0
- package/src/lib/action/get-message.ts +35 -0
- package/src/lib/action/make-call.ts +101 -0
- package/src/lib/action/phone-number-lookup.ts +39 -0
- package/src/lib/action/send-sms.ts +41 -0
- package/src/lib/common/index.ts +69 -0
- package/src/lib/trigger/new-call.ts +156 -0
- package/src/lib/trigger/new-incoming-sms.ts +123 -0
- package/src/lib/trigger/new-phone-number.ts +149 -0
- package/src/lib/trigger/new-recording.ts +140 -0
- package/src/lib/trigger/new-transcription.ts +140 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.twilioNewTranscription = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// Vendored from Activepieces packages/pieces/community/twilio/src/lib/trigger/new-transcription.ts (MIT).
|
|
6
|
+
// Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
|
|
7
|
+
const pieces_framework_1 = require("@agnocon/pieces-framework");
|
|
8
|
+
const pieces_common_1 = require("@agnocon/pieces-common");
|
|
9
|
+
const __1 = require("../..");
|
|
10
|
+
const polling = {
|
|
11
|
+
strategy: pieces_common_1.DedupeStrategy.TIMEBASED,
|
|
12
|
+
items(_a) {
|
|
13
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ auth, lastFetchEpochMS }) {
|
|
14
|
+
var _b, _c;
|
|
15
|
+
const isTest = lastFetchEpochMS === 0;
|
|
16
|
+
const account_sid = auth.username;
|
|
17
|
+
const auth_token = auth.password;
|
|
18
|
+
let currentUri = `/2010-04-01/Accounts/${account_sid}/Transcriptions.json?PageSize=${isTest ? 10 : 1000}`;
|
|
19
|
+
const results = [];
|
|
20
|
+
let stop = false;
|
|
21
|
+
do {
|
|
22
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
23
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
24
|
+
url: `https://api.twilio.com${currentUri}`,
|
|
25
|
+
authentication: {
|
|
26
|
+
type: pieces_common_1.AuthenticationType.BASIC,
|
|
27
|
+
username: account_sid,
|
|
28
|
+
password: auth_token,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
const payload = response.body;
|
|
32
|
+
const transcriptions = (_b = payload.transcriptions) !== null && _b !== void 0 ? _b : [];
|
|
33
|
+
for (const recording of transcriptions) {
|
|
34
|
+
const ts = new Date(recording.date_created).getTime();
|
|
35
|
+
if (recording.status !== 'completed')
|
|
36
|
+
continue;
|
|
37
|
+
if (isTest || ts > lastFetchEpochMS) {
|
|
38
|
+
results.push(recording);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
stop = true;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (isTest)
|
|
46
|
+
break;
|
|
47
|
+
currentUri = (_c = payload === null || payload === void 0 ? void 0 : payload.next_page_uri) !== null && _c !== void 0 ? _c : null;
|
|
48
|
+
} while (currentUri && !stop);
|
|
49
|
+
return results.map((recording) => {
|
|
50
|
+
return {
|
|
51
|
+
epochMilliSeconds: new Date(recording.date_created).getTime(),
|
|
52
|
+
data: recording,
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
exports.twilioNewTranscription = (0, pieces_framework_1.createTrigger)({
|
|
59
|
+
auth: __1.twilioAuth,
|
|
60
|
+
name: 'new_transcription',
|
|
61
|
+
displayName: 'New Transcription',
|
|
62
|
+
description: 'Triggers when a new call recording transcription is completed.',
|
|
63
|
+
aiMetadata: {
|
|
64
|
+
description: 'Fires when a call recording transcription reaches completed status on the Twilio account. Each event represents one finished transcription tied to a recording, including its transcribed text.',
|
|
65
|
+
},
|
|
66
|
+
props: {},
|
|
67
|
+
sampleData: {
|
|
68
|
+
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
69
|
+
"api_version": "2008-08-01",
|
|
70
|
+
"date_created": "Thu, 25 Aug 2011 20:59:45 +0000",
|
|
71
|
+
"date_updated": "Thu, 25 Aug 2011 20:59:45 +0000",
|
|
72
|
+
"duration": "10",
|
|
73
|
+
"price": "0.00000",
|
|
74
|
+
"price_unit": "USD",
|
|
75
|
+
"recording_sid": "REaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
76
|
+
"sid": "TRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
77
|
+
"status": "completed",
|
|
78
|
+
"transcription_text": null,
|
|
79
|
+
"type": "fast",
|
|
80
|
+
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions/TRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
|
|
81
|
+
},
|
|
82
|
+
type: pieces_framework_1.TriggerStrategy.POLLING,
|
|
83
|
+
onEnable(context) {
|
|
84
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
yield pieces_common_1.pollingHelper.onEnable(polling, {
|
|
86
|
+
auth: context.auth,
|
|
87
|
+
store: context.store,
|
|
88
|
+
propsValue: context.propsValue,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
onDisable(context) {
|
|
93
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
yield pieces_common_1.pollingHelper.onDisable(polling, {
|
|
95
|
+
auth: context.auth,
|
|
96
|
+
store: context.store,
|
|
97
|
+
propsValue: context.propsValue,
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
test(context) {
|
|
102
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
return yield pieces_common_1.pollingHelper.test(polling, context);
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
run(context) {
|
|
107
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
return yield pieces_common_1.pollingHelper.poll(polling, context);
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
//# sourceMappingURL=new-transcription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-transcription.js","sourceRoot":"","sources":["../../../src/lib/trigger/new-transcription.ts"],"names":[],"mappings":";;;;AAAA,0GAA0G;AAC1G,qEAAqE;AACrE,gEAKmC;AACnC,0DAOgC;AAChC,6BAAmC;AAkBnC,MAAM,OAAO,GAGT;IACF,QAAQ,EAAE,8BAAc,CAAC,SAAS;IAC5B,KAAK;qEAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE;;YACpC,MAAM,MAAM,GAAG,gBAAgB,KAAK,CAAC,CAAC;YACtC,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC;YAClC,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC;YAEjC,IAAI,UAAU,GAEH,wBAAwB,WAAW,iCAC5C,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAChB,EAAE,CAAC;YAEH,MAAM,OAAO,GAAG,EAAE,CAAC;YACnB,IAAI,IAAI,GAAG,KAAK,CAAC;YAEjB,GAAG,CAAC;gBACF,MAAM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O,CAAC,CAAC;QACpD,CAAC;KAAA;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@divyacon/piece-twilio",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "DivyaCon twilio connector",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src",
|
|
17
|
+
"LICENSE.MIT-AP"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"vendor": "node ../scripts/vendor-ap.mjs piece-twilio"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@agnocon/core-utils": "0.2.0",
|
|
25
|
+
"@agnocon/piece-types": "0.3.1",
|
|
26
|
+
"@agnocon/pieces-common": "0.12.8",
|
|
27
|
+
"@agnocon/pieces-framework": "0.36.0",
|
|
28
|
+
"tslib": "2.6.2"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "20.17.6",
|
|
32
|
+
"typescript": "5.5.4"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"agnocon": {
|
|
36
|
+
"originVersion": "0.4.8"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"tag": "latest"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"agnocon",
|
|
44
|
+
"connector"
|
|
45
|
+
]
|
|
6
46
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createCustomApiCallAction } from '@agnocon/pieces-common';
|
|
2
|
+
import { PieceAuth, createPiece } from '@agnocon/pieces-framework';
|
|
3
|
+
import { PieceCategory } from '@agnocon/pieces-framework';
|
|
4
|
+
import { twilioSendSms } from './lib/action/send-sms';
|
|
5
|
+
import { twilioNewIncomingSms } from './lib/trigger/new-incoming-sms';
|
|
6
|
+
import { twilioPhoneNumberLookup } from './lib/action/phone-number-lookup';
|
|
7
|
+
import { twilioMakeCall } from './lib/action/make-call';
|
|
8
|
+
import { twilioGetMessage } from './lib/action/get-message';
|
|
9
|
+
import { twilioDownloadRecordingMedia } from './lib/action/download-recording-media';
|
|
10
|
+
import { twilioNewPhoneNumber } from './lib/trigger/new-phone-number';
|
|
11
|
+
import { twilioNewRecording } from './lib/trigger/new-recording';
|
|
12
|
+
import { twilioNewTranscription } from './lib/trigger/new-transcription';
|
|
13
|
+
import { twilioNewCall } from './lib/trigger/new-call';
|
|
14
|
+
|
|
15
|
+
export const twilioAuth = PieceAuth.BasicAuth({
|
|
16
|
+
description: 'The authentication to use to connect to Twilio',
|
|
17
|
+
|
|
18
|
+
required: true,
|
|
19
|
+
username: {
|
|
20
|
+
displayName: 'Account SID',
|
|
21
|
+
description: 'The account SID to use to connect to Twilio',
|
|
22
|
+
},
|
|
23
|
+
password: {
|
|
24
|
+
displayName: 'Auth token',
|
|
25
|
+
description: 'The auth token to use to connect to Twilio',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const twilio = createPiece({
|
|
30
|
+
displayName: 'Twilio',
|
|
31
|
+
description:
|
|
32
|
+
'Cloud communications platform for building SMS, Voice & Messaging applications',
|
|
33
|
+
|
|
34
|
+
minimumSupportedRelease: '0.30.0',
|
|
35
|
+
logoUrl: 'https://cdn.activepieces.com/pieces/twilio.png',
|
|
36
|
+
auth: twilioAuth,
|
|
37
|
+
categories: [PieceCategory.COMMUNICATION],
|
|
38
|
+
actions: [
|
|
39
|
+
twilioSendSms,
|
|
40
|
+
twilioPhoneNumberLookup,
|
|
41
|
+
twilioMakeCall,
|
|
42
|
+
twilioGetMessage,
|
|
43
|
+
twilioDownloadRecordingMedia,
|
|
44
|
+
createCustomApiCallAction({
|
|
45
|
+
baseUrl: () => 'https://api.twilio.com/2010-04-01',
|
|
46
|
+
auth: twilioAuth,
|
|
47
|
+
authMapping: async (auth) => ({
|
|
48
|
+
Authorization: `Basic ${Buffer.from(
|
|
49
|
+
`${auth.username}:${
|
|
50
|
+
auth.password
|
|
51
|
+
}`
|
|
52
|
+
).toString('base64')}`,
|
|
53
|
+
}),
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
authors: ["kishanprmr","MoShizzle","khaledmashaly","abuaboud"],
|
|
57
|
+
triggers: [twilioNewIncomingSms,
|
|
58
|
+
twilioNewPhoneNumber,
|
|
59
|
+
twilioNewRecording,
|
|
60
|
+
twilioNewTranscription,
|
|
61
|
+
twilioNewCall
|
|
62
|
+
],
|
|
63
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod, httpClient, AuthenticationType, QueryParams } from '@agnocon/pieces-common';
|
|
3
|
+
import { twilioAuth } from '../..';
|
|
4
|
+
|
|
5
|
+
export const twilioDownloadRecordingMedia = createAction({
|
|
6
|
+
auth: twilioAuth,
|
|
7
|
+
name: 'download_recording_media',
|
|
8
|
+
displayName: 'Download Recording Media',
|
|
9
|
+
description: 'Download the media file for a specific recording.',
|
|
10
|
+
audience: 'both',
|
|
11
|
+
aiMetadata: { description: 'Downloads the audio file for a specific Twilio call recording by its SID, returning it as a file (MP3 or WAV). Use to retrieve recorded call audio for storage or further processing; requires the recording SID (starting with "RE"). Read-only and idempotent.', idempotent: true },
|
|
12
|
+
props: {
|
|
13
|
+
recording_sid: Property.ShortText({
|
|
14
|
+
displayName: 'Recording SID',
|
|
15
|
+
description: 'The unique identifier (SID) of the recording to download. It starts with "RE".',
|
|
16
|
+
required: true,
|
|
17
|
+
}),
|
|
18
|
+
format: Property.StaticDropdown({
|
|
19
|
+
displayName: 'Format',
|
|
20
|
+
description: 'The desired audio format for the download file.',
|
|
21
|
+
required: false,
|
|
22
|
+
defaultValue: 'mp3',
|
|
23
|
+
options: {
|
|
24
|
+
options: [
|
|
25
|
+
{ label: 'MP3', value: 'mp3' },
|
|
26
|
+
{ label: 'WAV', value: 'wav' },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
channels: Property.StaticDropdown({
|
|
31
|
+
displayName: 'Channels',
|
|
32
|
+
description: 'Specify whether to download a mono or dual-channel file. Note: Dual-channel may not be available for all recordings.',
|
|
33
|
+
required: false,
|
|
34
|
+
options: {
|
|
35
|
+
options: [
|
|
36
|
+
{ label: 'Mono', value: 1 },
|
|
37
|
+
{ label: 'Dual', value: 2 },
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
async run(context) {
|
|
43
|
+
const { recording_sid, format, channels } = context.propsValue;
|
|
44
|
+
const account_sid = context.auth.username;
|
|
45
|
+
const auth_token = context.auth.password;
|
|
46
|
+
|
|
47
|
+
const fileFormat = format ?? 'mp3';
|
|
48
|
+
const path = `Recordings/${recording_sid}.${fileFormat}`;
|
|
49
|
+
|
|
50
|
+
const queryParams: QueryParams = {};
|
|
51
|
+
if (channels) {
|
|
52
|
+
queryParams['RequestedChannels'] = channels.toString();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const response = await httpClient.sendRequest<ArrayBuffer>({
|
|
56
|
+
method: HttpMethod.GET,
|
|
57
|
+
url: `https://api.twilio.com/2010-04-01/Accounts/${account_sid}/${path}`,
|
|
58
|
+
queryParams: queryParams,
|
|
59
|
+
authentication: {
|
|
60
|
+
type: AuthenticationType.BASIC,
|
|
61
|
+
username: account_sid,
|
|
62
|
+
password: auth_token,
|
|
63
|
+
},
|
|
64
|
+
responseType: 'arraybuffer',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const fileData = Buffer.from(response.body);
|
|
68
|
+
|
|
69
|
+
return await context.files.write({
|
|
70
|
+
fileName: `${recording_sid}.${fileFormat}`,
|
|
71
|
+
data: fileData,
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod } from '@agnocon/pieces-common';
|
|
3
|
+
import { callTwilioApi } from '../common';
|
|
4
|
+
import { twilioAuth } from '../..';
|
|
5
|
+
|
|
6
|
+
export const twilioGetMessage = createAction({
|
|
7
|
+
auth: twilioAuth,
|
|
8
|
+
name: 'get_message',
|
|
9
|
+
description: 'Retrieves the details of a specific message.',
|
|
10
|
+
audience: 'both',
|
|
11
|
+
aiMetadata: { description: 'Fetches the full details and status of a single Twilio message by its SID. Use to check delivery status or inspect a known message; requires the message SID (starting with "SM" or "MM"). Read-only and idempotent.', idempotent: true },
|
|
12
|
+
displayName: 'Get Message',
|
|
13
|
+
props: {
|
|
14
|
+
message_sid: Property.ShortText({
|
|
15
|
+
displayName: 'Message SID',
|
|
16
|
+
description: 'The unique identifier (SID) of the message to retrieve. It starts with "SM" or "MM".',
|
|
17
|
+
required: true,
|
|
18
|
+
}),
|
|
19
|
+
},
|
|
20
|
+
async run(context) {
|
|
21
|
+
const { message_sid } = context.propsValue;
|
|
22
|
+
const account_sid = context.auth.username;
|
|
23
|
+
const auth_token = context.auth.password;
|
|
24
|
+
|
|
25
|
+
const path = `Messages/${message_sid}.json`;
|
|
26
|
+
|
|
27
|
+
const response = await callTwilioApi(
|
|
28
|
+
HttpMethod.GET,
|
|
29
|
+
path,
|
|
30
|
+
{ account_sid, auth_token }
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return response.body;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod } from '@agnocon/pieces-common';
|
|
3
|
+
import { callTwilioApi, twilioCommon } from '../common';
|
|
4
|
+
import { twilioAuth } from '../..';
|
|
5
|
+
|
|
6
|
+
export const twilioMakeCall = createAction({
|
|
7
|
+
auth: twilioAuth,
|
|
8
|
+
name: 'make_call',
|
|
9
|
+
description: 'Call a number and say a message.',
|
|
10
|
+
audience: 'both',
|
|
11
|
+
aiMetadata: { description: 'Places an outbound voice call from a Twilio number that reads a text-to-speech message to the recipient. Use to deliver a spoken notification or alert by phone. Requires both numbers in E.164 format and the message text; each call places a real, billable phone call, so it is not idempotent.', idempotent: false },
|
|
12
|
+
displayName: 'Call Phone',
|
|
13
|
+
props: {
|
|
14
|
+
from: twilioCommon.phone_number,
|
|
15
|
+
to: Property.ShortText({
|
|
16
|
+
displayName: 'To',
|
|
17
|
+
description: 'The phone number to call. Must be in E.164 format (e.g., +15558675310).',
|
|
18
|
+
required: true,
|
|
19
|
+
}),
|
|
20
|
+
message: Property.LongText({
|
|
21
|
+
displayName: 'Message to Say',
|
|
22
|
+
description: 'The text message to be converted to speech and spoken to the recipient.',
|
|
23
|
+
required: true,
|
|
24
|
+
}),
|
|
25
|
+
voice: Property.StaticDropdown({
|
|
26
|
+
displayName: 'Voice',
|
|
27
|
+
description: 'The voice to use for the text-to-speech message.',
|
|
28
|
+
required: false,
|
|
29
|
+
options: {
|
|
30
|
+
options: [
|
|
31
|
+
{ label: 'Alice (Default)', value: 'alice' },
|
|
32
|
+
{ label: 'Man', value: 'man' },
|
|
33
|
+
{ label: 'Woman', value: 'woman' },
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
language: Property.StaticDropdown({
|
|
38
|
+
displayName: 'Language',
|
|
39
|
+
description: 'The language to use for the text-to-speech message.',
|
|
40
|
+
required: false,
|
|
41
|
+
options: {
|
|
42
|
+
options: [
|
|
43
|
+
{ label: 'English (US)', value: 'en-US' },
|
|
44
|
+
{ label: 'English (UK)', value: 'en-GB' },
|
|
45
|
+
{ label: 'Spanish', value: 'es-ES' },
|
|
46
|
+
{ label: 'French', value: 'fr-FR' },
|
|
47
|
+
{ label: 'German', value: 'de-DE' },
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
sendDigits: Property.ShortText({
|
|
52
|
+
displayName: 'Send DTMF Tones',
|
|
53
|
+
description: "A string of keys to dial after the call is connected. Use 'w' for a half-second pause.",
|
|
54
|
+
required: false,
|
|
55
|
+
}),
|
|
56
|
+
timeout: Property.Number({
|
|
57
|
+
displayName: 'Timeout (seconds)',
|
|
58
|
+
description: 'The number of seconds to let the phone ring before assuming no answer. Default is 60.',
|
|
59
|
+
required: false,
|
|
60
|
+
})
|
|
61
|
+
},
|
|
62
|
+
async run(context) {
|
|
63
|
+
const { from, to, message, voice, language, sendDigits, timeout } = context.propsValue;
|
|
64
|
+
|
|
65
|
+
const account_sid = context.auth.username;
|
|
66
|
+
const auth_token = context.auth.password;
|
|
67
|
+
|
|
68
|
+
// Construct TwiML for the <Say> verb
|
|
69
|
+
const voiceAttr = voice ? ` voice="${voice}"` : '';
|
|
70
|
+
const langAttr = language ? ` language="${language}"` : '';
|
|
71
|
+
const escapedMessage = message
|
|
72
|
+
.replace(/&/g, '&')
|
|
73
|
+
.replace(/</g, '<')
|
|
74
|
+
.replace(/>/g, '>')
|
|
75
|
+
.replace(/"/g, '"')
|
|
76
|
+
.replace(/'/g, ''');
|
|
77
|
+
const twiml = `<Response><Say${voiceAttr}${langAttr}>${escapedMessage}</Say></Response>`;
|
|
78
|
+
|
|
79
|
+
const bodyParams: Record<string, unknown> = {
|
|
80
|
+
From: from,
|
|
81
|
+
To: to,
|
|
82
|
+
Twiml: twiml,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
if (sendDigits) {
|
|
86
|
+
bodyParams['SendDigits'] = sendDigits;
|
|
87
|
+
}
|
|
88
|
+
if (timeout) {
|
|
89
|
+
bodyParams['Timeout'] = timeout;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const response = await callTwilioApi(
|
|
93
|
+
HttpMethod.POST,
|
|
94
|
+
'Calls.json',
|
|
95
|
+
{ account_sid, auth_token },
|
|
96
|
+
bodyParams
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return response.body;
|
|
100
|
+
},
|
|
101
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { AuthenticationType, httpClient, HttpMethod } from '@agnocon/pieces-common';
|
|
3
|
+
import { twilioAuth } from '../..';
|
|
4
|
+
|
|
5
|
+
export const twilioPhoneNumberLookup = createAction({
|
|
6
|
+
auth: twilioAuth,
|
|
7
|
+
name: 'phone_number_lookup',
|
|
8
|
+
description: 'Lookup information about a phone number.',
|
|
9
|
+
audience: 'both',
|
|
10
|
+
aiMetadata: { description: 'Looks up carrier and line-type intelligence for a single phone number via the Twilio Lookup API. Use to validate or enrich a number (e.g. detect mobile vs landline, carrier) before messaging or calling it. Read-only and idempotent.', idempotent: true },
|
|
11
|
+
displayName: 'Phone Number Lookup',
|
|
12
|
+
props: {
|
|
13
|
+
phone_number:Property.ShortText({
|
|
14
|
+
displayName:'Phone Number',
|
|
15
|
+
required:true
|
|
16
|
+
})
|
|
17
|
+
},
|
|
18
|
+
async run(context) {
|
|
19
|
+
const { phone_number } = context.propsValue;
|
|
20
|
+
|
|
21
|
+
const account_sid = context.auth.username;
|
|
22
|
+
const auth_token = context.auth.password;
|
|
23
|
+
|
|
24
|
+
const response = await httpClient.sendRequest({
|
|
25
|
+
method:HttpMethod.GET,
|
|
26
|
+
url:`https://lookups.twilio.com/v2/PhoneNumbers/${encodeURIComponent(phone_number)}`,
|
|
27
|
+
authentication: {
|
|
28
|
+
type: AuthenticationType.BASIC,
|
|
29
|
+
username: account_sid,
|
|
30
|
+
password: auth_token,
|
|
31
|
+
},
|
|
32
|
+
queryParams:{
|
|
33
|
+
Fields:'line_type_intelligence'
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return response.body
|
|
38
|
+
},
|
|
39
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod } from '@agnocon/pieces-common';
|
|
3
|
+
import { callTwilioApi, twilioCommon } from '../common';
|
|
4
|
+
import { twilioAuth } from '../..';
|
|
5
|
+
|
|
6
|
+
export const twilioSendSms = createAction({
|
|
7
|
+
auth: twilioAuth,
|
|
8
|
+
name: 'send_sms',
|
|
9
|
+
description: 'Send a new SMS message',
|
|
10
|
+
audience: 'both',
|
|
11
|
+
aiMetadata: { description: 'Sends an SMS text message from a Twilio phone number to a recipient. Use to notify or message a person by text. Requires the destination number, message body, and a Twilio-owned sender number; sending costs money and delivers a separate message on every call, so it is not idempotent.', idempotent: false },
|
|
12
|
+
displayName: 'Send SMS',
|
|
13
|
+
props: {
|
|
14
|
+
from: twilioCommon.phone_number,
|
|
15
|
+
body: Property.ShortText({
|
|
16
|
+
description: 'The body of the message to send',
|
|
17
|
+
displayName: 'Message Body',
|
|
18
|
+
required: true,
|
|
19
|
+
}),
|
|
20
|
+
to: Property.ShortText({
|
|
21
|
+
description: 'The phone number to send the message to',
|
|
22
|
+
displayName: 'To',
|
|
23
|
+
required: true,
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
async run(context) {
|
|
27
|
+
const { body, to, from } = context.propsValue;
|
|
28
|
+
const account_sid = context.auth.username;
|
|
29
|
+
const auth_token = context.auth.password;
|
|
30
|
+
return await callTwilioApi(
|
|
31
|
+
HttpMethod.POST,
|
|
32
|
+
'Messages.json',
|
|
33
|
+
{ account_sid, auth_token },
|
|
34
|
+
{
|
|
35
|
+
From: from,
|
|
36
|
+
Body: body,
|
|
37
|
+
To: to,
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Property,
|
|
3
|
+
BasicAuthPropertyValue,
|
|
4
|
+
} from '@agnocon/pieces-framework';
|
|
5
|
+
import {
|
|
6
|
+
HttpMethod,
|
|
7
|
+
HttpMessageBody,
|
|
8
|
+
httpClient,
|
|
9
|
+
AuthenticationType,
|
|
10
|
+
} from '@agnocon/pieces-common';
|
|
11
|
+
import { twilioAuth } from '../..';
|
|
12
|
+
|
|
13
|
+
export const twilioCommon = {
|
|
14
|
+
phone_number: Property.Dropdown({
|
|
15
|
+
auth: twilioAuth,
|
|
16
|
+
description: 'The phone number to send the message from',
|
|
17
|
+
displayName: 'From',
|
|
18
|
+
required: true,
|
|
19
|
+
refreshers: [],
|
|
20
|
+
options: async ({ auth }) => {
|
|
21
|
+
if (!auth) {
|
|
22
|
+
return {
|
|
23
|
+
disabled: true,
|
|
24
|
+
placeholder: 'connect your account first',
|
|
25
|
+
options: [],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const basicAuthProperty = auth;
|
|
30
|
+
const response = await callTwilioApi<{
|
|
31
|
+
incoming_phone_numbers: {
|
|
32
|
+
phone_number: string;
|
|
33
|
+
friendly_name: string;
|
|
34
|
+
}[];
|
|
35
|
+
}>(HttpMethod.GET, 'IncomingPhoneNumbers.json', {
|
|
36
|
+
account_sid: basicAuthProperty.username,
|
|
37
|
+
auth_token: basicAuthProperty.password,
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
disabled: false,
|
|
41
|
+
options: response.body.incoming_phone_numbers.map((number: any) => ({
|
|
42
|
+
value: number.phone_number,
|
|
43
|
+
label: number.friendly_name,
|
|
44
|
+
})),
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const callTwilioApi = async <T extends HttpMessageBody>(
|
|
51
|
+
method: HttpMethod,
|
|
52
|
+
path: string,
|
|
53
|
+
auth: { account_sid: string; auth_token: string },
|
|
54
|
+
body?: any
|
|
55
|
+
) => {
|
|
56
|
+
return await httpClient.sendRequest<T>({
|
|
57
|
+
method,
|
|
58
|
+
url: `https://api.twilio.com/2010-04-01/Accounts/${auth.account_sid}/${path}`,
|
|
59
|
+
authentication: {
|
|
60
|
+
type: AuthenticationType.BASIC,
|
|
61
|
+
username: auth.account_sid,
|
|
62
|
+
password: auth.auth_token,
|
|
63
|
+
},
|
|
64
|
+
headers: {
|
|
65
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
66
|
+
},
|
|
67
|
+
body: body,
|
|
68
|
+
});
|
|
69
|
+
};
|