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.
This commit is contained in:
@@ -167,6 +167,10 @@ warelay supports running on the same phone number you message from—you chat wi
|
||||
| Key | Type & default | Notes |
|
||||
| --- | --- | --- |
|
||||
| `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.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. |
|
||||
|
||||
@@ -46,8 +46,8 @@ export type WarelayConfig = {
|
||||
logging?: LoggingConfig;
|
||||
inbound?: {
|
||||
allowFrom?: string[]; // E.164 numbers allowed to trigger auto-reply (without whatsapp:)
|
||||
samePhoneMarker?: string; // Prefix for same-phone mode messages (default: "[same-phone]")
|
||||
samePhoneResponsePrefix?: string; // Prefix auto-added to replies in same-phone mode (e.g., "🦞")
|
||||
messagePrefix?: string; // Prefix added to all inbound messages (default: "[warelay]" if no allowFrom, else "")
|
||||
responsePrefix?: string; // Prefix auto-added to all outbound replies (e.g., "🦞")
|
||||
timestampPrefix?: boolean; // Prepend compact timestamp to messages (default: false)
|
||||
timestampTimezone?: string; // IANA timezone for timestamp (default: UTC), e.g., "Europe/Vienna"
|
||||
transcribeAudio?: {
|
||||
@@ -143,8 +143,8 @@ const WarelaySchema = z.object({
|
||||
inbound: z
|
||||
.object({
|
||||
allowFrom: z.array(z.string()).optional(),
|
||||
samePhoneMarker: z.string().optional(),
|
||||
samePhoneResponsePrefix: z.string().optional(),
|
||||
messagePrefix: z.string().optional(),
|
||||
responsePrefix: z.string().optional(),
|
||||
timestampPrefix: z.boolean().optional(),
|
||||
timestampTimezone: z.string().optional(),
|
||||
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
|
||||
// The marker can be customized via config (default: "[same-phone]")
|
||||
const samePhoneMarker = cfg.inbound?.samePhoneMarker ?? "[same-phone]";
|
||||
const bodyForCommand = isSamePhoneMode
|
||||
? `${timestampStr}${samePhoneMarker} ${msg.body}`
|
||||
: `${timestampStr}${msg.body}`;
|
||||
// Build message prefix: explicit config > default based on allowFrom
|
||||
// If allowFrom is configured, user likely has a specific setup - no default prefix
|
||||
// If no allowFrom, add "[warelay]" so AI knows it's coming through warelay
|
||||
let messagePrefix = cfg.inbound?.messagePrefix;
|
||||
if (messagePrefix === undefined) {
|
||||
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)(
|
||||
{
|
||||
@@ -608,12 +612,12 @@ export async function monitorWebProvider(
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Apply same-phone response prefix if configured and in same-phone mode
|
||||
const samePhoneResponsePrefix = cfg.inbound?.samePhoneResponsePrefix;
|
||||
if (isSamePhoneMode && samePhoneResponsePrefix && replyResult.text) {
|
||||
// Apply response prefix if configured (for all messages)
|
||||
const responsePrefix = cfg.inbound?.responsePrefix;
|
||||
if (responsePrefix && replyResult.text) {
|
||||
// Only add prefix if not already present
|
||||
if (!replyResult.text.startsWith(samePhoneResponsePrefix)) {
|
||||
replyResult.text = `${samePhoneResponsePrefix} ${replyResult.text}`;
|
||||
if (!replyResult.text.startsWith(responsePrefix)) {
|
||||
replyResult.text = `${responsePrefix} ${replyResult.text}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user