Generalize prefix config: messagePrefix + responsePrefix
Replaces samePhoneMarker/samePhoneResponsePrefix with: - messagePrefix: prefix for all inbound messages - Default: '[warelay]' if no allowFrom, else '' - responsePrefix: prefix for all outbound replies Also adds timestamp options: - timestampPrefix: boolean to enable [Nov 29 06:30] format - timestampTimezone: IANA timezone (default UTC) Updated README with new config table entries.main
parent
26e02a9b8b
commit
7564c4e7f4
|
|
@ -167,6 +167,10 @@ warelay supports running on the same phone number you message from—you chat wi
|
||||||
| Key | Type & default | Notes |
|
| Key | Type & default | Notes |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `inbound.allowFrom` | `string[]` (default: empty) | E.164 numbers allowed to trigger auto-reply (no `whatsapp:`); `"*"` allows any sender. |
|
| `inbound.allowFrom` | `string[]` (default: empty) | E.164 numbers allowed to trigger auto-reply (no `whatsapp:`); `"*"` allows any sender. |
|
||||||
|
| `inbound.messagePrefix` | `string` (default: `"[warelay]"` if no allowFrom, else `""`) | Prefix added to all inbound messages before passing to command. |
|
||||||
|
| `inbound.responsePrefix` | `string` (default: —) | Prefix auto-added to all outbound replies (e.g., `"🦞"`). |
|
||||||
|
| `inbound.timestampPrefix` | `boolean` (default: `false`) | Prepend compact timestamp `[Nov 29 06:30]` to messages. |
|
||||||
|
| `inbound.timestampTimezone` | `string` (default: `"UTC"`) | IANA timezone for timestamp (e.g., `"Europe/Vienna"`). |
|
||||||
| `inbound.reply.mode` | `"text"` \| `"command"` (default: —) | Reply style. |
|
| `inbound.reply.mode` | `"text"` \| `"command"` (default: —) | Reply style. |
|
||||||
| `inbound.reply.text` | `string` (default: —) | Used when `mode=text`; templating supported. |
|
| `inbound.reply.text` | `string` (default: —) | Used when `mode=text`; templating supported. |
|
||||||
| `inbound.reply.command` | `string[]` (default: —) | Argv for `mode=command`; each element templated. Stdout (trimmed) is sent. |
|
| `inbound.reply.command` | `string[]` (default: —) | Argv for `mode=command`; each element templated. Stdout (trimmed) is sent. |
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ export type WarelayConfig = {
|
||||||
logging?: LoggingConfig;
|
logging?: LoggingConfig;
|
||||||
inbound?: {
|
inbound?: {
|
||||||
allowFrom?: string[]; // E.164 numbers allowed to trigger auto-reply (without whatsapp:)
|
allowFrom?: string[]; // E.164 numbers allowed to trigger auto-reply (without whatsapp:)
|
||||||
samePhoneMarker?: string; // Prefix for same-phone mode messages (default: "[same-phone]")
|
messagePrefix?: string; // Prefix added to all inbound messages (default: "[warelay]" if no allowFrom, else "")
|
||||||
samePhoneResponsePrefix?: string; // Prefix auto-added to replies in same-phone mode (e.g., "🦞")
|
responsePrefix?: string; // Prefix auto-added to all outbound replies (e.g., "🦞")
|
||||||
timestampPrefix?: boolean; // Prepend compact timestamp to messages (default: false)
|
timestampPrefix?: boolean; // Prepend compact timestamp to messages (default: false)
|
||||||
timestampTimezone?: string; // IANA timezone for timestamp (default: UTC), e.g., "Europe/Vienna"
|
timestampTimezone?: string; // IANA timezone for timestamp (default: UTC), e.g., "Europe/Vienna"
|
||||||
transcribeAudio?: {
|
transcribeAudio?: {
|
||||||
|
|
@ -143,8 +143,8 @@ const WarelaySchema = z.object({
|
||||||
inbound: z
|
inbound: z
|
||||||
.object({
|
.object({
|
||||||
allowFrom: z.array(z.string()).optional(),
|
allowFrom: z.array(z.string()).optional(),
|
||||||
samePhoneMarker: z.string().optional(),
|
messagePrefix: z.string().optional(),
|
||||||
samePhoneResponsePrefix: z.string().optional(),
|
responsePrefix: z.string().optional(),
|
||||||
timestampPrefix: z.boolean().optional(),
|
timestampPrefix: z.boolean().optional(),
|
||||||
timestampTimezone: z.string().optional(),
|
timestampTimezone: z.string().optional(),
|
||||||
transcribeAudio: z
|
transcribeAudio: z
|
||||||
|
|
|
||||||
|
|
@ -576,12 +576,16 @@ export async function monitorWebProvider(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prefix body with marker in same-phone mode so the assistant knows to prefix replies
|
// Build message prefix: explicit config > default based on allowFrom
|
||||||
// The marker can be customized via config (default: "[same-phone]")
|
// If allowFrom is configured, user likely has a specific setup - no default prefix
|
||||||
const samePhoneMarker = cfg.inbound?.samePhoneMarker ?? "[same-phone]";
|
// If no allowFrom, add "[warelay]" so AI knows it's coming through warelay
|
||||||
const bodyForCommand = isSamePhoneMode
|
let messagePrefix = cfg.inbound?.messagePrefix;
|
||||||
? `${timestampStr}${samePhoneMarker} ${msg.body}`
|
if (messagePrefix === undefined) {
|
||||||
: `${timestampStr}${msg.body}`;
|
const hasAllowFrom = (cfg.inbound?.allowFrom?.length ?? 0) > 0;
|
||||||
|
messagePrefix = hasAllowFrom ? "" : "[warelay]";
|
||||||
|
}
|
||||||
|
const prefixStr = messagePrefix ? `${messagePrefix} ` : "";
|
||||||
|
const bodyForCommand = `${timestampStr}${prefixStr}${msg.body}`;
|
||||||
|
|
||||||
const replyResult = await (replyResolver ?? getReplyFromConfig)(
|
const replyResult = await (replyResolver ?? getReplyFromConfig)(
|
||||||
{
|
{
|
||||||
|
|
@ -608,12 +612,12 @@ export async function monitorWebProvider(
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Apply same-phone response prefix if configured and in same-phone mode
|
// Apply response prefix if configured (for all messages)
|
||||||
const samePhoneResponsePrefix = cfg.inbound?.samePhoneResponsePrefix;
|
const responsePrefix = cfg.inbound?.responsePrefix;
|
||||||
if (isSamePhoneMode && samePhoneResponsePrefix && replyResult.text) {
|
if (responsePrefix && replyResult.text) {
|
||||||
// Only add prefix if not already present
|
// Only add prefix if not already present
|
||||||
if (!replyResult.text.startsWith(samePhoneResponsePrefix)) {
|
if (!replyResult.text.startsWith(responsePrefix)) {
|
||||||
replyResult.text = `${samePhoneResponsePrefix} ${replyResult.text}`;
|
replyResult.text = `${responsePrefix} ${replyResult.text}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue