getpatter 0.6.1 → 0.6.3

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/README.md CHANGED
@@ -92,7 +92,7 @@ cp .env.example .env
92
92
  # Edit .env with your API keys
93
93
  ```
94
94
 
95
- > **Telnyx:** Telnyx is a fully supported telephony provider alternative to Twilio. Both carriers receive equal support for DTMF, transfer, and metrics. Recording is Twilio-only.
95
+ > **Telnyx:** Telnyx is a fully supported telephony provider alternative to Twilio. Both carriers receive equal support for DTMF, transfer, and metrics. Recording parity is supported via Telnyx Call Control; consult the Telnyx portal for configuration details.
96
96
 
97
97
  ## Voice Modes
98
98
 
@@ -9,6 +9,7 @@ import {
9
9
  init_esm_shims();
10
10
  var TWILIO_API_BASE = "https://api.twilio.com/2010-04-01";
11
11
  var TELNYX_API_BASE = "https://api.telnyx.com/v2";
12
+ var PLIVO_API_BASE = "https://api.plivo.com/v1";
12
13
  async function configureTwilioNumber(accountSid, authToken, phoneNumber, voiceUrl) {
13
14
  const auth = `Basic ${Buffer.from(`${accountSid}:${authToken}`).toString("base64")}`;
14
15
  const listUrl = `${TWILIO_API_BASE}/Accounts/${accountSid}/IncomingPhoneNumbers.json?PhoneNumber=${encodeURIComponent(phoneNumber)}`;
@@ -57,9 +58,38 @@ async function configureTelnyxNumber(apiKey, connectionId, phoneNumber) {
57
58
  );
58
59
  }
59
60
  }
61
+ async function configurePlivoNumber(authId, authToken, phoneNumber, answerUrl) {
62
+ const auth = `Basic ${Buffer.from(`${authId}:${authToken}`).toString("base64")}`;
63
+ const base = `${PLIVO_API_BASE}/Account/${encodeURIComponent(authId)}`;
64
+ const appResp = await fetch(`${base}/Application/`, {
65
+ method: "POST",
66
+ headers: { Authorization: auth, "Content-Type": "application/json" },
67
+ body: JSON.stringify({
68
+ app_name: "patter-inbound",
69
+ answer_url: answerUrl,
70
+ answer_method: "POST"
71
+ })
72
+ });
73
+ if (!appResp.ok) {
74
+ throw new Error(`Plivo Application create failed: ${appResp.status} ${await appResp.text()}`);
75
+ }
76
+ const appBody = await appResp.json();
77
+ if (!appBody.app_id) {
78
+ getLogger().warn("Plivo Application create returned no app_id");
79
+ return;
80
+ }
81
+ const linkResp = await fetch(`${base}/Number/${encodeURIComponent(phoneNumber)}/`, {
82
+ method: "POST",
83
+ headers: { Authorization: auth, "Content-Type": "application/json" },
84
+ body: JSON.stringify({ app_id: appBody.app_id })
85
+ });
86
+ if (!linkResp.ok) {
87
+ throw new Error(`Plivo Number update failed: ${linkResp.status} ${await linkResp.text()}`);
88
+ }
89
+ }
60
90
  async function autoConfigureCarrier(params) {
61
91
  const log = getLogger();
62
- const provider = params.telephonyProvider ?? (params.twilioSid ? "twilio" : "telnyx");
92
+ const provider = params.telephonyProvider ?? (params.twilioSid ? "twilio" : params.plivoAuthId ? "plivo" : "telnyx");
63
93
  if (provider === "twilio" && params.twilioSid && params.twilioToken) {
64
94
  const voiceUrl = `https://${params.webhookHost}/webhooks/twilio/voice`;
65
95
  try {
@@ -78,10 +108,22 @@ async function autoConfigureCarrier(params) {
78
108
  } catch (err) {
79
109
  log.warn("Could not auto-configure Telnyx number: %s", err instanceof Error ? err.message : String(err));
80
110
  }
111
+ return;
112
+ }
113
+ if (provider === "plivo" && params.plivoAuthId && params.plivoAuthToken) {
114
+ const answerUrl = `https://${params.webhookHost}/webhooks/plivo/voice`;
115
+ try {
116
+ await configurePlivoNumber(params.plivoAuthId, params.plivoAuthToken, params.phoneNumber, answerUrl);
117
+ log.info("Plivo answer URL set to %s", answerUrl);
118
+ } catch (err) {
119
+ log.warn("Could not auto-configure Plivo answer URL: %s", err instanceof Error ? err.message : String(err));
120
+ log.info("Set the Plivo application answer URL manually to: %s", answerUrl);
121
+ }
81
122
  }
82
123
  }
83
124
  export {
84
125
  autoConfigureCarrier,
126
+ configurePlivoNumber,
85
127
  configureTelnyxNumber,
86
128
  configureTwilioNumber
87
129
  };