Sending messages from a website
After initialization, pass message to SenlerWidget.open(...) or SenlerWidget.updateRuntime(...). This sends a visitor message, not an automation message.
Prepare a message
message accepts { text, requestId?, startNewDialog?, autoSend? }. Text must be a nonempty string of up to 10,000 characters; requestId must be a nonempty string of up to 200 characters. autoSend: true sends after the widget is ready; false or omitting it only fills the input. Do not pass requestId for a draft: result events are intended for automatic sending, otherwise the loader waits for sending and reports an error after 10 seconds.
message.startNewDialog: true sends without the current dialog_id. Do not combine new-dialog creation and dialogId selection in one call: the new dialog takes priority. Other parameters.
Track sending and the response
When message.requestId is provided, the loader dispatches senler-widget:runtime-message-result. It links the site's request to message delivery and response completion without polling history.
const requestId = crypto.randomUUID();
window.addEventListener("senler-widget:runtime-message-result", (event) => {
if (event.detail.request_id !== requestId) return;
if (event.detail.status === "message_sent") {
console.log("Dialog", event.detail.dialog_id);
}
if (event.detail.status === "answered") {
console.log("The answer is ready");
}
if (["message_send_failed", "message_answer_failed", "preview_failed"].includes(
event.detail.status,
)) {
console.error(event.detail.error_message);
}
});
SenlerWidget.open({
message: {
text: "Make this text clearer.",
requestId,
startNewDialog: true,
autoSend: true,
},
});
Possible statuses:
| Status | Meaning |
|---|---|
accepted | The automatically sent message configuration was accepted by the widget, but sending has not started yet. |
sending | Sending started. |
message_sent | The message was sent and dialog_id is available. |
answered | The answer completed. |
message_send_failed | The message could not be sent. |
message_answer_failed | Answer generation failed. |
preview_failed | A preview could not be built for the associated edit flow. |
detail always contains request_id and status; dialog_id and error_message are included where applicable. The loader monitors two separate stages: the iframe has 10 seconds to become ready and accept the request; after delivery, the widget has another 10 seconds to report that sending started. A timeout at either stage produces message_send_failed. Open the dialog with SenlerWidget.open({ dialogId }) or SenlerWidget.selectDialog(dialogId).
For text editing, use the inline controller: it tracks requestId and returns a ready preview.