Interaction of the Widget with the Messenger Input Field
If you are developing integrations for Bitrix24 using AI tools (Codex, Claude Code, Cursor), connect to the MCP server so that the assistant can utilize the official REST documentation.
To work with text in the chat input field, use the methods $b24.parent.message.send. This is convenient when you need to:
- retrieve the current text from the chat
- insert prepared text into the input field
- do this safely, without directly interacting with the messenger interface
Call Format
$b24.parent.message.send(method, params)
Prerequisites Before Calls
- The application must be running inside the Bitrix24 frame.
- The SDK must be initialized via initializeB24Frame().
Example:
const $b24 = await B24Js.initializeB24Frame()
Method im:getImTextareaContent
The method im:getImTextareaContent returns the current text from the input field of the active chat.
Parameters
Required parameters are marked with *
|
Parameter |
Description |
|
requestId* |
Unique request ID. Create it using B24Js.Text.getUuidRfc4122() |
|
isSafely |
If |
|
safelyTime |
How long to wait for a response in milliseconds |
Example
const responseGet = await $b24.parent.message.send(
'im:getImTextareaContent',
{
requestId: B24Js.Text.getUuidRfc4122(),
isSafely: true,
safelyTime: 1500
}
)
The responseGet will contain the text from the input field. If an error occurs, the response will return an object with the following fields:
message— error text (JavaScript system message)requestId— the samerequestIdthat was passed in the request
Possible reasons for the error:
- failed to determine the current dialog
- the text field is unavailable
Method im:setImTextareaContent
The method im:setImTextareaContent inserts text into the input field of the active chat.
Parameters
Required parameters are marked with *
|
Parameter |
Description |
|
text* |
Text to insert into the input field |
|
requestId* |
Unique request ID. Create it using |
|
withNewLine |
If |
|
replace |
If |
|
isSafely |
If |
|
safelyTime |
How long to wait for a response in milliseconds |
Example
const responseSet = await $b24.parent.message.send(
'im:setImTextareaContent',
{
text: 'Hello from iframe!',
requestId: B24Js.Text.getUuidRfc4122(),
withNewLine: false,
replace: true,
isSafely: true,
safelyTime: 1500
}
)
The responseSet will contain the result of the insertion. If an error occurs, the response will return an object with the following fields:
message— error text (JavaScript system message)requestId— the samerequestIdthat was passed in the request
Possible reasons for the error:
- failed to determine the current dialog
- the text field is unavailable
Implementation Example
An example widget demonstrating both methods can be downloaded.
How the Example Works
- The SDK is connected in the browser via the UMD script
@bitrix24/b24jssdk. - Upon page load,
B24Js.initializeB24Frame()is called. - The Get text button sends
im:getImTextareaContentand retrieves the current text from the input field. - The Set text button sends
im:setImTextareaContentand inserts text into the chat. - The flags
withNewLineandreplaceare taken from checkboxes in the form. - The results of the requests are displayed in the
#logblock and in theconsole.