Webim (Custom Channel API) as an inbound channel
Creating a channel
On the control panel, click Channels → Inbound → Connect channel. In the Others section, select Webim (Custom Channel API).
Fill in the fields:
- Name — enter a name for the channel or leave it as default.
- Access token — leave empty.
- Email — specify the email address of the Webim service administrator account.
- Password — enter the password of the Webim service administrator account.
- Domain — enter the domain to which you are installing the Webim service. For example, for the account
https://examplecom.webim.ru
enter domain examplecom. - Branch — specify the project branch you want to deploy into the channel (
master
by default). You can also select a Git tag or enter a specific commit hash. - Deployment — select Automatic (whenever any change made to the project is saved) or Manual (using the Deploy button in the channel description line).
Click Create. Wait for the pop-up window with the result of the deployment. If it is successful chatbot is ready for use.
The script
Chat initialization options:
With messages
Webim requests the platform to initialize the chat. If the client has sent anything to the chat before the conversation starts, all their messages are combined into one and sent to the script for processing.
You can use the preProcess
handler to define a new session. For example:
init:
bind("preProcess", function($context){
if($context.session = {}){
// here we assume the session is new
}
})
Without messages
When a chat without any messages from the client is initialized, event: newChatStarted
is sent to the script. eventData
contains the Webim request.
Request example:
eventData = {
"chat": {
"id":
},
"location": {
"address":
},
"visitor": {
"id":
}
}
event: newChatStarted
reaction. This state will only be used to initialize variables.For example, client location obtained from eventData
is used in the script:
state: ConversationStart || noContext = true
event: newChatStarted
script:
$session.startNewSession = true;
if ($session.startNewSession){
createNewSession($request)
}
$session.location = $request.rawRequest.location;