Skip to main content

Webim (Custom Channel API) as an inbound channel

tip
Webim is an online consulting platform. Multiple channels can be used for communication: chat on the site, messengers, social media, chatbots, mobile applications and others. The platform also integrates with CRM and HelpDesk systems.

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).
caution
You have to deploy a script before starting the bot. At this stage, the system builds the bot, checks the script syntax, and performs tests.

Click Create. Wait for the pop-up window with the result of the deployment. If it is successful chatbot is ready for use.

tip
Specifying the administrator account data is necessary to collect the logs of dialogs with the agent. If the fields are not filled in, logs will be collected only until the transfer to the agent.
caution
After the channel is created, the Endpoint API is generated. Go to channel editing, copy the endpoint API, and send it to Webim.

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":
}
}
caution
Using bot replies for the user is excluded in the state where you catch the 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;