niahere 0.3.1 → 0.3.2
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/package.json +1 -1
- package/src/channels/common/chat-session.ts +56 -0
- package/src/channels/phone/index.ts +13 -4
- package/src/channels/phone/tools.ts +2 -2
- package/src/channels/slack.ts +62 -82
- package/src/channels/sms.ts +25 -35
- package/src/channels/telegram.ts +46 -54
- package/src/channels/whatsapp.ts +90 -122
- package/src/chat/identity.ts +1 -2
- package/src/cli/phone.ts +9 -6
- package/src/commands/init.ts +17 -14
- package/src/commands/service.ts +26 -7
- package/src/mcp/tools.ts +17 -33
- package/src/types/channel.ts +35 -6
- package/src/types/index.ts +1 -1
- package/src/utils/attachment.ts +8 -2
- package/src/utils/config.ts +12 -27
package/src/utils/config.ts
CHANGED
|
@@ -146,14 +146,10 @@ export function loadConfig(): Config {
|
|
|
146
146
|
const chSms = (ch.sms || {}) as Record<string, unknown>;
|
|
147
147
|
const chWa = (ch.whatsapp || {}) as Record<string, unknown>;
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
// legacy `channels.phone.<oldKey>` (the pre-refactor location), then env.
|
|
151
|
-
const twilioOrPhone = (newKey: string, oldKey: string, envKey: string | null): string | null => {
|
|
149
|
+
const twilioField = (key: string, envKey: string | null): string | null => {
|
|
152
150
|
const envVal = envKey ? process.env[envKey] : undefined;
|
|
153
151
|
if (envVal) return envVal;
|
|
154
|
-
|
|
155
|
-
if (typeof chPh[oldKey] === "string") return chPh[oldKey] as string;
|
|
156
|
-
return null;
|
|
152
|
+
return typeof chTw[key] === "string" ? (chTw[key] as string) : null;
|
|
157
153
|
};
|
|
158
154
|
|
|
159
155
|
const channelsEnabled = ch.enabled !== false;
|
|
@@ -174,11 +170,7 @@ export function loadConfig(): Config {
|
|
|
174
170
|
|
|
175
171
|
const slAppToken = process.env.SLACK_APP_TOKEN || (typeof chSl.app_token === "string" ? chSl.app_token : null);
|
|
176
172
|
|
|
177
|
-
|
|
178
|
-
const legacyChannelId =
|
|
179
|
-
process.env.SLACK_CHANNEL_ID || (typeof chSl.channel_id === "string" ? chSl.channel_id : null);
|
|
180
|
-
const slDmUserId =
|
|
181
|
-
process.env.SLACK_DM_USER_ID || (typeof chSl.dm_user_id === "string" ? chSl.dm_user_id : null) || legacyChannelId;
|
|
173
|
+
const slDmUserId = process.env.SLACK_DM_USER_ID || (typeof chSl.dm_user_id === "string" ? chSl.dm_user_id : null);
|
|
182
174
|
|
|
183
175
|
const slBotUserId = typeof chSl.bot_user_id === "string" ? chSl.bot_user_id : null;
|
|
184
176
|
const slBotName = typeof chSl.bot_name === "string" ? chSl.bot_name : null;
|
|
@@ -187,15 +179,12 @@ export function loadConfig(): Config {
|
|
|
187
179
|
const slWorkspaceUrl = typeof chSl.workspace_url === "string" ? chSl.workspace_url : null;
|
|
188
180
|
|
|
189
181
|
// --- Twilio shared config (used by phone, sms, whatsapp) ---
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
const twOwnerNumber = twilioOrPhone("owner_number", "owner_number", "PRIMARY_PHONE_USER");
|
|
197
|
-
const twPublicBaseUrl =
|
|
198
|
-
(twilioOrPhone("public_base_url", "public_base_url", "PUBLIC_BASE_URL") || "").replace(/\/$/, "") || null;
|
|
182
|
+
// Env vars take precedence over channels.twilio.* values.
|
|
183
|
+
const twSid = twilioField("sid", "TWILIO_SID");
|
|
184
|
+
const twSecret = twilioField("secret", "TWILIO_SECRET");
|
|
185
|
+
const twAuthToken = twilioField("auth_token", "TWILIO_AUTH_TOKEN");
|
|
186
|
+
const twOwnerNumber = twilioField("owner_number", "PRIMARY_PHONE_USER");
|
|
187
|
+
const twPublicBaseUrl = (twilioField("public_base_url", "PUBLIC_BASE_URL") || "").replace(/\/$/, "") || null;
|
|
199
188
|
|
|
200
189
|
const twPortRaw = process.env.PHONE_PORT ? Number(process.env.PHONE_PORT) : null;
|
|
201
190
|
const twPort =
|
|
@@ -203,23 +192,19 @@ export function loadConfig(): Config {
|
|
|
203
192
|
? twPortRaw
|
|
204
193
|
: typeof chTw.port === "number"
|
|
205
194
|
? chTw.port
|
|
206
|
-
:
|
|
207
|
-
? chPh.port
|
|
208
|
-
: DEFAULTS.channels.twilio.port;
|
|
195
|
+
: DEFAULTS.channels.twilio.port;
|
|
209
196
|
|
|
210
197
|
const twAllowlistRaw =
|
|
211
198
|
process.env.PHONE_ALLOWLIST ||
|
|
212
199
|
(Array.isArray(chTw.allowlist)
|
|
213
200
|
? (chTw.allowlist as unknown[]).filter((x): x is string => typeof x === "string").join(",")
|
|
214
|
-
:
|
|
215
|
-
? (chPh.allowlist as unknown[]).filter((x): x is string => typeof x === "string").join(",")
|
|
216
|
-
: "");
|
|
201
|
+
: "");
|
|
217
202
|
const twAllowlist = twAllowlistRaw
|
|
218
203
|
.split(",")
|
|
219
204
|
.map((s) => s.trim())
|
|
220
205
|
.filter((s) => s.length > 0);
|
|
221
206
|
|
|
222
|
-
// --- Phone (voice) — env vars
|
|
207
|
+
// --- Phone (voice) — env vars override config ---
|
|
223
208
|
const phFromNumber =
|
|
224
209
|
process.env.PHONE_FROM_NUMBER || (typeof chPh.from_number === "string" ? chPh.from_number : null);
|
|
225
210
|
const phOpenAiKey =
|