31 lines
846 B
JavaScript
31 lines
846 B
JavaScript
import crypto from "crypto";
|
|
import { resolveTenantId } from "../../2-identity/services/pipeline.js";
|
|
import { processMessage } from "../../2-identity/services/pipeline.js";
|
|
|
|
export async function handleSimSend(body) {
|
|
const { chat_id, from_phone, text } = body || {};
|
|
if (!chat_id || !from_phone || !text) {
|
|
return { status: 400, payload: { ok: false, error: "chat_id, from_phone, text are required" } };
|
|
}
|
|
|
|
const provider = "sim";
|
|
const message_id = crypto.randomUUID();
|
|
const tenantId = await resolveTenantId({
|
|
chat_id,
|
|
tenant_key: body?.tenant_key,
|
|
to_phone: body?.to_phone,
|
|
});
|
|
|
|
const result = await processMessage({
|
|
tenantId,
|
|
chat_id,
|
|
from: from_phone,
|
|
text,
|
|
provider,
|
|
message_id,
|
|
});
|
|
|
|
return { status: 200, payload: { ok: true, run_id: result.run_id, reply: result.reply } };
|
|
}
|
|
|