This site is no longer updated.Go to new Conversational Cloud docs

Webim as an incoming channel


Creating a channel

On the control panel click on Channels > Incoming > Create channel. In the Others section, select Webim.

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 branch of the project that you want to deploy in the channel, master by default.
  • Deploy — select Automatic (after each saving of the changes made to the project) or Manual (using the Publish button in the line with the description of the channel).

Please note the Deploy radio button. You have to deploy a script before starting the chatbot. At this stage, the system builds the chatbot, checks script syntax and performs tests.

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

Specifying the administrator account data is necessary to collect the logs of dialogues with the operator. If the fields are not filled in, logs will be collected only until the transfer to the operator.

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:

  • without client messages;
  • with client messages.

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":
    }
}

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;