@superdurable/connector-twilio-messaging 0.0.0-stage → 0.2.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 +21 -0
- package/README.md +90 -2
- package/dex-connector.json +139 -0
- package/dist/chunk-6KLMYDTX.js +173 -0
- package/dist/connection-BQ9-3dhC.d.ts +143 -0
- package/dist/index.d.ts +283 -0
- package/dist/index.js +991 -0
- package/dist/mock.d.ts +60 -0
- package/dist/mock.js +137 -0
- package/package.json +62 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,91 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Twilio Messaging TypeScript connector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@superdurable/connector-twilio-messaging` provides the `sendMessage` Mutation,
|
|
4
|
+
the `getMessage` Query, and the `messageReceived` poll Trigger for Dex
|
|
5
|
+
TypeScript applications. The package ships
|
|
6
|
+
manifest-generated contracts and Step factories; `src/client.ts` and
|
|
7
|
+
`src/operations.ts` implement the Twilio Messages HTTP behavior.
|
|
8
|
+
|
|
9
|
+
Install with `npm install @superdurable/connector-twilio-messaging@0.2.0`.
|
|
10
|
+
Use Node.js 22 or 24 and the released Connector SDK version in `package.json`.
|
|
11
|
+
|
|
12
|
+
## Connection
|
|
13
|
+
|
|
14
|
+
Create a Twilio account or subaccount in the [Twilio Console](https://console.twilio.com/).
|
|
15
|
+
In Dex Web **Connections**, set `accountSid` to the account's `AC` SID from
|
|
16
|
+
**Account Dashboard > Account Info**. Choose `auth-token` and save the secret
|
|
17
|
+
`auth_token` from that panel, or choose `api-key` and save `api_key_sid` and
|
|
18
|
+
secret `api_key_secret` from **Account > API keys & tokens**. The key must
|
|
19
|
+
belong to the same account and Region. `defaultSender` can be an E.164 number,
|
|
20
|
+
`whatsapp:` number, or Messaging Service `MG` SID; blank requires `sender` on
|
|
21
|
+
each request. Leave `endpoint` and `maxResponseBytes` blank for their manifest
|
|
22
|
+
defaults. `pollInterval` is the delay between `messageReceived` polls, a Go
|
|
23
|
+
duration of at least 5 seconds. Secrets are resolved for every call and never belong in Flow input.
|
|
24
|
+
Stored credentials without `auth_method` use `auth-token`; a rejected static
|
|
25
|
+
credential requires updating the connection rather than an automatic refresh.
|
|
26
|
+
|
|
27
|
+
The runnable [text-message-delivery example](examples/text-message-delivery/README.md)
|
|
28
|
+
uses `newProjectConnection(project, ConnectionName)` and the generated
|
|
29
|
+
`newSendMessageStep` and `newGetMessageStep`. Its static connection name is
|
|
30
|
+
`twilio-messaging`.
|
|
31
|
+
|
|
32
|
+
## messageReceived Trigger
|
|
33
|
+
|
|
34
|
+
`messageReceived` polls the account's Messages list with the TypeScript poll
|
|
35
|
+
Trigger kit (`@superdurable/connectors-sdk/pollingtrigger`, Connector SDK
|
|
36
|
+
0.12.0) at behavior parity with the Go connector, and delivers one
|
|
37
|
+
`MessageReceivedEvent` per inbound message: the safe message view plus its
|
|
38
|
+
text. The binding's saved `to` (an E.164 number or `whatsapp:+E.164` sender;
|
|
39
|
+
blank receives every inbound message of the account) is sent as the list's
|
|
40
|
+
`To` filter, and outbound messages are never delivered. The first poll records
|
|
41
|
+
the last two minutes as a baseline. Later polls relist from the `date_sent`
|
|
42
|
+
watermark minus two minutes, skip SIDs already delivered, hold an MMS still in
|
|
43
|
+
`receiving` for up to ten minutes, and deliver at most 500 messages per page,
|
|
44
|
+
oldest first. A 429 pauses the connection for `Retry-After`; an undecodable
|
|
45
|
+
cursor, or one for another account or number, records a new baseline. The
|
|
46
|
+
Trigger event ID is `twilio-message-<SID>`. The
|
|
47
|
+
[connector README](../README.md#messagereceived-trigger) describes pagination
|
|
48
|
+
and window halving.
|
|
49
|
+
|
|
50
|
+
The cursor token and keyed snapshot match the Go connector byte for byte, so Go
|
|
51
|
+
and TypeScript replicas share a binding's cursor, and a message a Go replica
|
|
52
|
+
recorded in the inbox replays in TypeScript.
|
|
53
|
+
[`examples/message-received/app.ts`](examples/message-received/app.ts) records
|
|
54
|
+
each message in the binding's project Trigger inbox before the watermark
|
|
55
|
+
commits:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const runner = newProjectMessageTriggerRunner(project, connection, [{
|
|
59
|
+
bindingName: MessageReceivedTriggerBinding, target: newDexFlowTriggerTarget(client, flow, acceptEveryInboundMessage, resolveFlowId, mapToFlowInput, { logger: options.logger }),
|
|
60
|
+
}], options.logger);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`newMessageTriggerRunner` takes targets and cursor stores directly, and
|
|
64
|
+
`newMessageReceivedTrigger` runs one binding with an in-memory cursor, so every
|
|
65
|
+
start records a new baseline. See the
|
|
66
|
+
[message-received example](examples/message-received/README.md).
|
|
67
|
+
|
|
68
|
+
## Behavior
|
|
69
|
+
|
|
70
|
+
`sendMessage` sends `To`, an optional body, ordered media URLs, and either
|
|
71
|
+
`From` or `MessagingServiceSid`. Form values use Go-compatible query escaping,
|
|
72
|
+
including `%2A` for `*` and an unescaped `~`. Twilio has no Messages create idempotency key.
|
|
73
|
+
The SDK fence records a heartbeat before dispatch and permits a resend only
|
|
74
|
+
after proof of no send or Twilio's 429 or 503 response. A valid 2xx Message
|
|
75
|
+
selects `accepted`; a conclusive 4xx selects `providerRejected`; an ambiguous
|
|
76
|
+
transport or response selects uncertainty. `getMessage` reads a Message SID,
|
|
77
|
+
retries transport, 408, 429, and 5xx failures, and selects `found`, `notFound`,
|
|
78
|
+
`providerRejected`, or `invalidResponse` for final results. Unwired optional
|
|
79
|
+
branches fail the Flow.
|
|
80
|
+
|
|
81
|
+
Outputs contain only Twilio's safe message metadata. The body, media URLs,
|
|
82
|
+
credential values, and provider error prose are excluded. Status and request
|
|
83
|
+
count behavior is replayed against Go recordings in
|
|
84
|
+
`conformance/connectors/twilio/messaging/scenarios.json`.
|
|
85
|
+
|
|
86
|
+
Run `npm ci && npm run check` in this directory. The Trigger tests replay the
|
|
87
|
+
Go fetcher and runner tests against a local Messages list fake and compare
|
|
88
|
+
cursor tokens, snapshot keys, request queries, and event payloads with
|
|
89
|
+
Go-printed values. The examples' Dex Worker and Client integration checks need
|
|
90
|
+
`dexcli dev` and `DEX_FLOW_SERVICE_ADDRESS`. Live Twilio authorization, message
|
|
91
|
+
creation, delivery, and Messages listing were not verified.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
{
|
|
2
|
+
"connectorId": "twilio-messaging",
|
|
3
|
+
"releaseTag": "connectors/twilio/messaging/go/v0.24.0",
|
|
4
|
+
"package": {
|
|
5
|
+
"ecosystem": "npm",
|
|
6
|
+
"name": "@superdurable/connector-twilio-messaging",
|
|
7
|
+
"version": "0.2.0"
|
|
8
|
+
},
|
|
9
|
+
"factories": [
|
|
10
|
+
{
|
|
11
|
+
"name": "newSendMessageStep",
|
|
12
|
+
"kind": "mutation",
|
|
13
|
+
"operationId": "sendMessage",
|
|
14
|
+
"inputType": "SendMessageInput",
|
|
15
|
+
"description": "Send one SMS, MMS, or WhatsApp message from a Twilio number or Messaging Service to one recipient; synchronous durability makes the single-dispatch checkpoint visible to retries because Twilio provides no message idempotency key.",
|
|
16
|
+
"fields": {
|
|
17
|
+
"stepType": "stepType",
|
|
18
|
+
"annotations": "annotations",
|
|
19
|
+
"connectionName": "connectionName",
|
|
20
|
+
"resultAttribute": "resultAttribute"
|
|
21
|
+
},
|
|
22
|
+
"branches": [
|
|
23
|
+
{
|
|
24
|
+
"id": "accepted",
|
|
25
|
+
"field": "accepted",
|
|
26
|
+
"optional": false
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "providerRejected",
|
|
30
|
+
"field": "providerRejected",
|
|
31
|
+
"optional": true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "uncertain",
|
|
35
|
+
"field": "uncertain",
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "defect",
|
|
40
|
+
"field": "defect",
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"inputSchema": {
|
|
45
|
+
"additionalProperties": false,
|
|
46
|
+
"description": "SendMessageInput describes one message to one recipient.",
|
|
47
|
+
"properties": {
|
|
48
|
+
"body": {
|
|
49
|
+
"description": "Body is the message text, at most 1600 characters. It may be empty only when MediaURLs is set.",
|
|
50
|
+
"type": "string"
|
|
51
|
+
},
|
|
52
|
+
"mediaUrls": {
|
|
53
|
+
"description": "MediaURLs lists at most 10 public HTTPS URLs that Twilio fetches and attaches, which makes an SMS an MMS.",
|
|
54
|
+
"items": {
|
|
55
|
+
"type": "string"
|
|
56
|
+
},
|
|
57
|
+
"type": "array"
|
|
58
|
+
},
|
|
59
|
+
"sender": {
|
|
60
|
+
"description": "Sender overrides the connection's defaultSender with an E.164 number, a whatsapp: address, or an MG Messaging Service SID. Blank uses defaultSender.",
|
|
61
|
+
"type": "string"
|
|
62
|
+
},
|
|
63
|
+
"to": {
|
|
64
|
+
"description": "To is the recipient: an E.164 number such as +14155550100, or whatsapp:+14155550100.",
|
|
65
|
+
"type": "string"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"required": [
|
|
69
|
+
"to"
|
|
70
|
+
],
|
|
71
|
+
"type": "object"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"name": "newGetMessageStep",
|
|
76
|
+
"kind": "query",
|
|
77
|
+
"operationId": "getMessage",
|
|
78
|
+
"inputType": "GetMessageInput",
|
|
79
|
+
"description": "Read one message by SID, including its delivery status and Twilio error code.",
|
|
80
|
+
"fields": {
|
|
81
|
+
"stepType": "stepType",
|
|
82
|
+
"annotations": "annotations",
|
|
83
|
+
"connectionName": "connectionName",
|
|
84
|
+
"resultAttribute": "resultAttribute"
|
|
85
|
+
},
|
|
86
|
+
"branches": [
|
|
87
|
+
{
|
|
88
|
+
"id": "found",
|
|
89
|
+
"field": "found",
|
|
90
|
+
"optional": false
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"id": "notFound",
|
|
94
|
+
"field": "notFound",
|
|
95
|
+
"optional": true
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"id": "providerRejected",
|
|
99
|
+
"field": "providerRejected",
|
|
100
|
+
"optional": true
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"id": "invalidResponse",
|
|
104
|
+
"field": "invalidResponse",
|
|
105
|
+
"optional": true
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"id": "defect",
|
|
109
|
+
"field": "defect",
|
|
110
|
+
"optional": true
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
"inputSchema": {
|
|
114
|
+
"additionalProperties": false,
|
|
115
|
+
"description": "GetMessageInput identifies one message.",
|
|
116
|
+
"properties": {
|
|
117
|
+
"messageSid": {
|
|
118
|
+
"description": "MessageSID is the SM or MM message SID returned by sendMessage.",
|
|
119
|
+
"type": "string"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"required": [
|
|
123
|
+
"messageSid"
|
|
124
|
+
],
|
|
125
|
+
"type": "object"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"name": "defineMessageReceivedTriggerBinding",
|
|
130
|
+
"kind": "trigger",
|
|
131
|
+
"triggerName": "messageReceived",
|
|
132
|
+
"fields": {
|
|
133
|
+
"connectionName": "connectionName",
|
|
134
|
+
"bindingName": "bindingName",
|
|
135
|
+
"configurationUI": "configurationUI"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// src/generated/definitions.ts
|
|
2
|
+
var ConnectorID = "twilio-messaging";
|
|
3
|
+
var ProviderID = "twilio";
|
|
4
|
+
var SendMessageBranch = {
|
|
5
|
+
Accepted: "accepted",
|
|
6
|
+
ProviderRejected: "providerRejected",
|
|
7
|
+
Uncertain: "uncertain",
|
|
8
|
+
Defect: "defect"
|
|
9
|
+
};
|
|
10
|
+
var SendMessageBranchAccepted = SendMessageBranch.Accepted;
|
|
11
|
+
var SendMessageBranchProviderRejected = SendMessageBranch.ProviderRejected;
|
|
12
|
+
var SendMessageBranchUncertain = SendMessageBranch.Uncertain;
|
|
13
|
+
var SendMessageBranchDefect = SendMessageBranch.Defect;
|
|
14
|
+
var SendMessageDefinition = {
|
|
15
|
+
operation: { connectorId: ConnectorID, operationId: "sendMessage" },
|
|
16
|
+
branches: [
|
|
17
|
+
{ id: "accepted", description: "Twilio created the message and returned its SID; delivery status arrives later through getMessage." },
|
|
18
|
+
{ id: "providerRejected", description: "Twilio conclusively rejected the message, such as an invalid To number, an unverified trial recipient, an unsubscribed recipient, or an unusable sender; nothing was sent.", optional: true },
|
|
19
|
+
{ id: "uncertain", description: "The request was dispatched but its outcome cannot be confirmed; Twilio has no idempotency key, so the message may exist and must not be resent automatically.", optional: true },
|
|
20
|
+
{ id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
|
|
21
|
+
],
|
|
22
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 5, totalDurationMs: 12e4 } },
|
|
23
|
+
repeatOnUnknown: "limited",
|
|
24
|
+
maxSends: 3
|
|
25
|
+
};
|
|
26
|
+
var GetMessageBranch = {
|
|
27
|
+
Found: "found",
|
|
28
|
+
NotFound: "notFound",
|
|
29
|
+
ProviderRejected: "providerRejected",
|
|
30
|
+
InvalidResponse: "invalidResponse",
|
|
31
|
+
Defect: "defect"
|
|
32
|
+
};
|
|
33
|
+
var GetMessageBranchFound = GetMessageBranch.Found;
|
|
34
|
+
var GetMessageBranchNotFound = GetMessageBranch.NotFound;
|
|
35
|
+
var GetMessageBranchProviderRejected = GetMessageBranch.ProviderRejected;
|
|
36
|
+
var GetMessageBranchInvalidResponse = GetMessageBranch.InvalidResponse;
|
|
37
|
+
var GetMessageBranchDefect = GetMessageBranch.Defect;
|
|
38
|
+
var GetMessageDefinition = {
|
|
39
|
+
operation: { connectorId: ConnectorID, operationId: "getMessage" },
|
|
40
|
+
branches: [
|
|
41
|
+
{ id: "found", description: "The message exists and its current status was read." },
|
|
42
|
+
{ id: "notFound", description: "The account has no message with that SID.", optional: true },
|
|
43
|
+
{ id: "providerRejected", description: "Twilio conclusively rejected the message query.", optional: true },
|
|
44
|
+
{ id: "invalidResponse", description: "Twilio returned an invalid or oversized message response.", optional: true },
|
|
45
|
+
{ id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
|
|
46
|
+
],
|
|
47
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/generated/models.ts
|
|
51
|
+
import { z } from "zod";
|
|
52
|
+
import { SecretString } from "@superdurable/connectors-sdk";
|
|
53
|
+
var goTimeJSONPattern = /^(\d{4})-(\d{2})-(\d{2})T(\d{1,2}):(\d{2}):(\d{2})(?:[.,](\d+))?(Z|([+-])(\d{2}):(\d{2}))$/;
|
|
54
|
+
function isGoTimeJSON(value) {
|
|
55
|
+
const match = goTimeJSONPattern.exec(value);
|
|
56
|
+
if (!match) return false;
|
|
57
|
+
const [, yearText, monthText, dayText, hourText, minuteText, secondText, , zone, , zoneHourText, zoneMinuteText] = match;
|
|
58
|
+
const year = Number(yearText);
|
|
59
|
+
const month = Number(monthText);
|
|
60
|
+
const day = Number(dayText);
|
|
61
|
+
const isLeap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
62
|
+
const monthDays = [31, isLeap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
63
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= monthDays[month - 1] && Number(hourText) <= 23 && Number(minuteText) <= 59 && Number(secondText) <= 59 && (zone === "Z" || Number(zoneHourText) <= 24 && Number(zoneMinuteText) <= 60);
|
|
64
|
+
}
|
|
65
|
+
function canonicalGoTimeJSON(value) {
|
|
66
|
+
const match = goTimeJSONPattern.exec(value);
|
|
67
|
+
const [, year, month, day, hour, minute, second, fraction, zone, sign, zoneHour, zoneMinute] = match;
|
|
68
|
+
const clock = year + "-" + month + "-" + day + "T" + hour.padStart(2, "0") + ":" + minute + ":" + second;
|
|
69
|
+
const digits = (fraction ?? "").slice(0, 9).replace(/0+$/, "");
|
|
70
|
+
const offsetMinutes = zone === "Z" ? 0 : (Number(zoneHour) * 60 + Number(zoneMinute)) * (sign === "+" ? 1 : -1);
|
|
71
|
+
if (Math.abs(offsetMinutes) >= 1440) return value;
|
|
72
|
+
const offset = offsetMinutes === 0 ? "Z" : (offsetMinutes > 0 ? "+" : "-") + String(Math.floor(Math.abs(offsetMinutes) / 60)).padStart(2, "0") + ":" + String(Math.abs(offsetMinutes) % 60).padStart(2, "0");
|
|
73
|
+
return clock + (digits ? "." + digits : "") + offset;
|
|
74
|
+
}
|
|
75
|
+
var GoTimeJSONSchema = z.string().refine(isGoTimeJSON, "invalid Go time.Time JSON timestamp").transform(canonicalGoTimeJSON);
|
|
76
|
+
var ConfigSchema = z.object({
|
|
77
|
+
"accountSid": z.string(),
|
|
78
|
+
"defaultSender": z.string().optional(),
|
|
79
|
+
"endpoint": z.string().optional(),
|
|
80
|
+
"maxResponseBytes": z.number().int().optional(),
|
|
81
|
+
"pollIntervalMs": z.number().int().optional()
|
|
82
|
+
});
|
|
83
|
+
function decodeCredentials(value) {
|
|
84
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("credential fields are invalid");
|
|
85
|
+
const fields = value;
|
|
86
|
+
const allowed = /* @__PURE__ */ new Set(["auth_method", "api_key_sid", "api_key_secret", "auth_token"]);
|
|
87
|
+
if (Object.keys(fields).some((key) => !allowed.has(key))) throw new TypeError("stored credential does not match the connector credential fields");
|
|
88
|
+
if (fields["api_key_sid"] != null && !(typeof fields["api_key_sid"] === "string")) throw new TypeError("credential api_key_sid has an invalid type");
|
|
89
|
+
if (fields["api_key_secret"] != null && !(typeof fields["api_key_secret"] === "string")) throw new TypeError("credential api_key_secret has an invalid type");
|
|
90
|
+
if (fields["auth_token"] != null && !(typeof fields["auth_token"] === "string")) throw new TypeError("credential auth_token has an invalid type");
|
|
91
|
+
const selectedMethod = fields["auth_method"] ?? "";
|
|
92
|
+
if (typeof selectedMethod !== "string") throw new TypeError("credential auth_method is invalid");
|
|
93
|
+
const method = selectedMethod || "auth-token";
|
|
94
|
+
const credentials = { authMethodId: method };
|
|
95
|
+
if (method === "auth-token") {
|
|
96
|
+
if (!fields["auth_token"]) throw new TypeError("credential auth_token is required");
|
|
97
|
+
if (fields["auth_token"]) credentials.authToken = new SecretString(fields["auth_token"]);
|
|
98
|
+
} else if (method === "api-key") {
|
|
99
|
+
if (!fields["api_key_sid"]) throw new TypeError("credential api_key_sid is required");
|
|
100
|
+
if (fields["api_key_sid"]) credentials.apiKeySid = fields["api_key_sid"];
|
|
101
|
+
if (!fields["api_key_secret"]) throw new TypeError("credential api_key_secret is required");
|
|
102
|
+
if (fields["api_key_secret"]) credentials.apiKeySecret = new SecretString(fields["api_key_secret"]);
|
|
103
|
+
} else {
|
|
104
|
+
throw new TypeError("credential auth_method is invalid");
|
|
105
|
+
}
|
|
106
|
+
return credentials;
|
|
107
|
+
}
|
|
108
|
+
var SendMessageInputSchema = z.strictObject({
|
|
109
|
+
"to": z.string(),
|
|
110
|
+
"body": z.string().optional(),
|
|
111
|
+
"mediaUrls": z.array(z.string()).optional(),
|
|
112
|
+
"sender": z.string().optional()
|
|
113
|
+
});
|
|
114
|
+
var MessageSchema = z.strictObject({
|
|
115
|
+
"sid": z.string().optional(),
|
|
116
|
+
"accountSid": z.string(),
|
|
117
|
+
"messagingServiceSid": z.string().optional(),
|
|
118
|
+
"from": z.string().optional(),
|
|
119
|
+
"to": z.string(),
|
|
120
|
+
"status": z.string().optional(),
|
|
121
|
+
"direction": z.string().optional(),
|
|
122
|
+
"errorCode": z.number().int().optional(),
|
|
123
|
+
"segmentCount": z.number().int().optional(),
|
|
124
|
+
"mediaCount": z.number().int().optional(),
|
|
125
|
+
"price": z.string().optional(),
|
|
126
|
+
"priceUnit": z.string().optional(),
|
|
127
|
+
"createdAt": GoTimeJSONSchema,
|
|
128
|
+
"sentAt": GoTimeJSONSchema,
|
|
129
|
+
"updatedAt": GoTimeJSONSchema
|
|
130
|
+
});
|
|
131
|
+
var GetMessageInputSchema = z.strictObject({
|
|
132
|
+
"messageSid": z.string()
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// src/generated/connection.ts
|
|
136
|
+
import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
|
|
137
|
+
var Connection = class {
|
|
138
|
+
/** Stable provider and connection name. */
|
|
139
|
+
reference;
|
|
140
|
+
/** Bound provider operations. */
|
|
141
|
+
operations;
|
|
142
|
+
/** Validate a reference and bind operations. */
|
|
143
|
+
constructor(reference, operations) {
|
|
144
|
+
this.reference = ConnectionRefSchema.parse(reference);
|
|
145
|
+
if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
|
|
146
|
+
if (!operations) throw new TypeError("connector operations are required");
|
|
147
|
+
this.operations = operations;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
function newConnection(client, reference) {
|
|
151
|
+
if (!client) throw new TypeError("connector client is required");
|
|
152
|
+
return new Connection(reference, client);
|
|
153
|
+
}
|
|
154
|
+
function newConnectionWithOperations(operations, reference) {
|
|
155
|
+
return new Connection(reference, operations);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export {
|
|
159
|
+
ConnectorID,
|
|
160
|
+
ProviderID,
|
|
161
|
+
SendMessageBranch,
|
|
162
|
+
SendMessageDefinition,
|
|
163
|
+
GetMessageBranch,
|
|
164
|
+
GetMessageDefinition,
|
|
165
|
+
ConfigSchema,
|
|
166
|
+
decodeCredentials,
|
|
167
|
+
SendMessageInputSchema,
|
|
168
|
+
MessageSchema,
|
|
169
|
+
GetMessageInputSchema,
|
|
170
|
+
Connection,
|
|
171
|
+
newConnection,
|
|
172
|
+
newConnectionWithOperations
|
|
173
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { SecretString, Mutation, Query, ConnectionRef } from '@superdurable/connectors-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/** Connector configuration; omitted fields use manifest defaults. */
|
|
5
|
+
interface Config {
|
|
6
|
+
/** Non-secret Account SID from https://console.twilio.com > Account Dashboard > Account Info; it is AC followed by 32 hexadecimal characters and names the account or subaccount that owns the sender and every sent message. Required: both authentication methods send it in the Messages API path. */
|
|
7
|
+
accountSid: string;
|
|
8
|
+
/** Sender used when a send names none. Copy an SMS-capable number from https://console.twilio.com/us1/develop/phone-numbers/manage/incoming (Phone Numbers > Manage > Active numbers) in E.164 form such as +14155550100, a WhatsApp sender from Messaging > Senders > WhatsApp senders written whatsapp:+14155550100, or a Messaging Service SID (MG followed by 32 hexadecimal characters) from Messaging > Services; short codes and alphanumeric sender IDs need a Messaging Service. Not secret. Blank means every send must name its own sender. */
|
|
9
|
+
defaultSender?: string;
|
|
10
|
+
/** Twilio REST API base URL including the 2010-04-01 version segment; leave blank for the United States (US1) Region. Enter a regional URL such as https://api.dublin.ie1.twilio.com/2010-04-01 only when the account and its credentials were created in that Twilio Region. */
|
|
11
|
+
endpoint?: string;
|
|
12
|
+
/** Maximum complete Twilio API response in bytes. Leave blank to keep the displayed safety limit; enter a positive integer only to change it. An oversized getMessage response selects invalidResponse, and an oversized response to an accepted send selects uncertain. */
|
|
13
|
+
maxResponseBytes?: number;
|
|
14
|
+
/** Delay between messageReceived Trigger polls of the Twilio Messages list, as a Go duration of at least 5s such as 15s or 2m. Shorter intervals deliver inbound messages sooner and send more list requests, which count against the account's API concurrency limit. Leave blank to keep the displayed interval. Runtime value in milliseconds. */
|
|
15
|
+
pollIntervalMs?: number;
|
|
16
|
+
}
|
|
17
|
+
/** Runtime schema for manifest configuration. */
|
|
18
|
+
declare const ConfigSchema: z.ZodObject<{
|
|
19
|
+
accountSid: z.ZodString;
|
|
20
|
+
defaultSender: z.ZodOptional<z.ZodString>;
|
|
21
|
+
endpoint: z.ZodOptional<z.ZodString>;
|
|
22
|
+
maxResponseBytes: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
pollIntervalMs: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
/** Private connector credentials resolved by the host. */
|
|
26
|
+
interface Credentials {
|
|
27
|
+
/** Selected authorization method. */
|
|
28
|
+
authMethodId?: string;
|
|
29
|
+
/** Non-secret API key SID shown after Create API key at https://console.twilio.com/us1/account/keys-credentials/api-keys (Account > API keys & tokens); SK followed by 32 hexadecimal characters. The key must belong to the Account SID above and to the Twilio Region of the endpoint. It is stored with its secret, so replacing a key replaces both without an application restart. */
|
|
30
|
+
apiKeySid?: string;
|
|
31
|
+
/** Secret shown once after Create API key at https://console.twilio.com/us1/account/keys-credentials/api-keys; 32 characters. Twilio never shows it again, so create a new key when it is lost. Stored only in this credential field. */
|
|
32
|
+
apiKeySecret?: SecretString;
|
|
33
|
+
/** Secret primary Auth Token from https://console.twilio.com > Account Dashboard > Account Info > Auth Token > Show; 32 hexadecimal characters for the Account SID above. Stored only in this credential field; after a Twilio rotation, paste the new token here. */
|
|
34
|
+
authToken?: SecretString;
|
|
35
|
+
}
|
|
36
|
+
/** Decode private credential fields for the selected authorization method. */
|
|
37
|
+
declare function decodeCredentials(value: unknown): Credentials;
|
|
38
|
+
/** SendMessageInput describes one message to one recipient. */
|
|
39
|
+
interface SendMessageInput {
|
|
40
|
+
/** To is the recipient: an E.164 number such as +14155550100, or whatsapp:+14155550100. */
|
|
41
|
+
"to": string;
|
|
42
|
+
/** Body is the message text, at most 1600 characters. It may be empty only when MediaURLs is set. */
|
|
43
|
+
"body"?: string | undefined;
|
|
44
|
+
/** MediaURLs lists at most 10 public HTTPS URLs that Twilio fetches and attaches, which makes an SMS an MMS. */
|
|
45
|
+
"mediaUrls"?: Array<string> | undefined;
|
|
46
|
+
/** Sender overrides the connection's defaultSender with an E.164 number, a whatsapp: address, or
|
|
47
|
+
* an MG Messaging Service SID. Blank uses defaultSender. */
|
|
48
|
+
"sender"?: string | undefined;
|
|
49
|
+
}
|
|
50
|
+
/** Message is the connector-safe subset of a Twilio Message resource.
|
|
51
|
+
*
|
|
52
|
+
* It never contains the message body, media URLs, or Twilio's error message
|
|
53
|
+
* text. After sendMessage selects providerRejected or uncertain, SID and
|
|
54
|
+
* Status are empty and the value echoes the requested account, sender, and
|
|
55
|
+
* recipient; ErrorCode then holds the rejection's Twilio error code. */
|
|
56
|
+
interface Message {
|
|
57
|
+
/** SID is Twilio's message identifier: SM or MM followed by 32 hexadecimal characters. */
|
|
58
|
+
"sid"?: string | undefined;
|
|
59
|
+
/** AccountSID is the AC account that owns the message. */
|
|
60
|
+
"accountSid": string;
|
|
61
|
+
/** MessagingServiceSID is the MG Messaging Service that sent the message, when one was used. */
|
|
62
|
+
"messagingServiceSid"?: string | undefined;
|
|
63
|
+
/** From is the sending number, WhatsApp address, short code, or alphanumeric sender ID.
|
|
64
|
+
* It is empty until a Messaging Service chooses a sender. */
|
|
65
|
+
"from"?: string | undefined;
|
|
66
|
+
/** To is the recipient in E.164 form, or a whatsapp: address. */
|
|
67
|
+
"to": string;
|
|
68
|
+
/** Status is Twilio's delivery status. */
|
|
69
|
+
"status"?: "accepted" | "canceled" | "delivered" | "failed" | "queued" | "read" | "received" | "receiving" | "scheduled" | "sending" | "sent" | "undelivered" | (string & {}) | undefined;
|
|
70
|
+
/** Direction is Twilio's direction value, such as outbound-api. */
|
|
71
|
+
"direction"?: string | undefined;
|
|
72
|
+
/** ErrorCode is Twilio's numeric error code, documented at https://www.twilio.com/docs/api/errors; zero means none. */
|
|
73
|
+
"errorCode"?: number | undefined;
|
|
74
|
+
/** SegmentCount is the number of SMS segments Twilio billed or will bill. */
|
|
75
|
+
"segmentCount"?: number | undefined;
|
|
76
|
+
/** MediaCount is the number of media items attached to the message. */
|
|
77
|
+
"mediaCount"?: number | undefined;
|
|
78
|
+
/** Price is Twilio's decimal price, usually negative, once known. */
|
|
79
|
+
"price"?: string | undefined;
|
|
80
|
+
/** PriceUnit is the ISO 4217 currency of Price. */
|
|
81
|
+
"priceUnit"?: string | undefined;
|
|
82
|
+
/** CreatedAt is when Twilio created the message; zero means unknown. */
|
|
83
|
+
"createdAt": string;
|
|
84
|
+
/** SentAt is when Twilio sent the message; zero means not yet sent. */
|
|
85
|
+
"sentAt": string;
|
|
86
|
+
/** UpdatedAt is when Twilio last changed the message; zero means unknown. */
|
|
87
|
+
"updatedAt": string;
|
|
88
|
+
}
|
|
89
|
+
/** GetMessageInput identifies one message. */
|
|
90
|
+
interface GetMessageInput {
|
|
91
|
+
/** MessageSID is the SM or MM message SID returned by sendMessage. */
|
|
92
|
+
"messageSid": string;
|
|
93
|
+
}
|
|
94
|
+
/** Runtime validator for SendMessageInput. */
|
|
95
|
+
declare const SendMessageInputSchema: z.ZodObject<{
|
|
96
|
+
to: z.ZodString;
|
|
97
|
+
body: z.ZodOptional<z.ZodString>;
|
|
98
|
+
mediaUrls: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
99
|
+
sender: z.ZodOptional<z.ZodString>;
|
|
100
|
+
}, z.core.$strict>;
|
|
101
|
+
/** Runtime validator for Message. */
|
|
102
|
+
declare const MessageSchema: z.ZodObject<{
|
|
103
|
+
sid: z.ZodOptional<z.ZodString>;
|
|
104
|
+
accountSid: z.ZodString;
|
|
105
|
+
messagingServiceSid: z.ZodOptional<z.ZodString>;
|
|
106
|
+
from: z.ZodOptional<z.ZodString>;
|
|
107
|
+
to: z.ZodString;
|
|
108
|
+
status: z.ZodOptional<z.ZodString>;
|
|
109
|
+
direction: z.ZodOptional<z.ZodString>;
|
|
110
|
+
errorCode: z.ZodOptional<z.ZodNumber>;
|
|
111
|
+
segmentCount: z.ZodOptional<z.ZodNumber>;
|
|
112
|
+
mediaCount: z.ZodOptional<z.ZodNumber>;
|
|
113
|
+
price: z.ZodOptional<z.ZodString>;
|
|
114
|
+
priceUnit: z.ZodOptional<z.ZodString>;
|
|
115
|
+
createdAt: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
116
|
+
sentAt: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
117
|
+
updatedAt: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
118
|
+
}, z.core.$strict>;
|
|
119
|
+
/** Runtime validator for GetMessageInput. */
|
|
120
|
+
declare const GetMessageInputSchema: z.ZodObject<{
|
|
121
|
+
messageSid: z.ZodString;
|
|
122
|
+
}, z.core.$strict>;
|
|
123
|
+
|
|
124
|
+
/** Typed operations supplied by a client or mock. */
|
|
125
|
+
interface Operations {
|
|
126
|
+
/** Invoke sendMessage through this connection. */
|
|
127
|
+
sendMessage(): Mutation<SendMessageInput, Message>;
|
|
128
|
+
/** Invoke getMessage through this connection. */
|
|
129
|
+
getMessage(): Query<GetMessageInput, Message>;
|
|
130
|
+
}
|
|
131
|
+
/** Named connector connection kept outside Flow state. */
|
|
132
|
+
declare class Connection<BoundOperations = Operations> {
|
|
133
|
+
/** Stable provider and connection name. */
|
|
134
|
+
readonly reference: ConnectionRef;
|
|
135
|
+
/** Bound provider operations. */
|
|
136
|
+
readonly operations: BoundOperations;
|
|
137
|
+
/** Validate a reference and bind operations. */
|
|
138
|
+
constructor(reference: ConnectionRef, operations: BoundOperations);
|
|
139
|
+
}
|
|
140
|
+
/** Bind scripted operations to a named connection. */
|
|
141
|
+
declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
|
|
142
|
+
|
|
143
|
+
export { type Config as C, type GetMessageInput as G, type Message as M, type Operations as O, type SendMessageInput as S, type Credentials as a, Connection as b, ConfigSchema as c, GetMessageInputSchema as d, MessageSchema as e, SendMessageInputSchema as f, decodeCredentials as g, newConnectionWithOperations as n };
|