Receive Messages - Callback Type

    LINE WORKS provides an interface for communications between message bots and users.

    After receiving messages sent from a user, the message bot delivers them to the client's message receiving server.

    The following callback event types are available: message, join, leave, joined, left and postback. More types will be added later.

    Type Description
    message Plain text message
    join A bot was invited to a team/group or 1:N chatroom.
    leave A bot left the team/group or 1:N chatroom.
    joined A member was invited to a team/group or 1:N chatroom.
    left A member left the team/group or 1:N chatroom.
    postback Postback type message

    Header Information

    The header information is as follows:

    • Protocol: HTTPS
    • HTTP Method: POST
    • Content type: application/json; charset=UTF-8

    An example is shown below.

    POST /callback HTTP/1.1
    Content-type: application/json; charset=UTF-8
    X-WORKS-Signature: /xZcekiWAICrwq5Dc+wBwBf6Gq33il-jRAo01KAVO3/U=
    X-WORKS-BotNo: 123
    { "type": 0, … }

    The following procedure describes how to check if the message sent from the message server is falsified.

    1. Use your API ID as a secret key to encode the content body sent from the message server with HMAC-SHA256 algorithm.
    2. Encode the result encoded in step 1 with BASE64.
    3. Compare the result with the X-WORKS-Signature header value;

    if the two values are the same, it is determined that the message is not falsified. If they do not match, the message is damaged or illegally modified and thus should not be used.

    Please be careful not to let your API ID become public.

    The following example shows how to check if the message is falsified in Java.

    String apiId = ...;        // API ID string
    String httpRequestBody = ...; // Request body string
    SecretKeySpec key = new SecretKeySpec(apiId.getBytes(), "HmacSHA256");
    Mac mac = Mac.getInstance("HmacSHA256");
    byte[] source = httpRequestBody.getBytes("UTF-8");
    String signature = Base64.encodeBase64String(mac.doFinal(source));

    The bot number is returned in the X-WORKS-BotNo header information.

    Callbacks invoked when the bot is invited by a user

    If the bot is set to public on the organization chart when the message bot domain is added, a user can invite the bot.

    When the conversation begins, "Start" is typed in the chat window and "start" is also passed through the message callback's content.postback.

    The following example shows the callback invoked when a conversation begins.



    • The value of the content.text, which is "start" in the above example, changes based on the user's language settings.