Updated on 2025-11-13 GMT+08:00

Receiving and Processing Messages Sent on LINE

Function

This interface is invoked to receive and process messages sent on LINE.

Usage Description

  • Prerequisites

    The LINE channel has been correctly created in the AICC, and the AICC callback URL is correctly entered on the LINE developer platform.

Interface Authentication

Use the SHA256 algorithm to generate an authentication character string based on the request body and the value of appSecret in the channel configuration, and compare the character string with that in the LINE request header x-line-signature.

/**
     * Verify the LINE signature information.
     *
     * @param signature Signature information carried in the message sent on LINE.
     * @param requestBody Request body parameters.
     * @param channelSecret Encrypted key.
     * @return Verification result. The value true indicates that the verification is successful, and the value false indicates that the verification fails.
     */
    private boolean validateSignature(String signature, String requestBody, String channelSecret) {
        try {
            SecretKeySpec key = new SecretKeySpec(channelSecret.getBytes(StandardCharsets.UTF_8), privateKeyAlgorithm);
            Mac mac = Mac.getInstance(privateKeyAlgorithm);
            mac.init(key);
            byte[] source = requestBody.getBytes(StandardCharsets.UTF_8);
            String encodeResult = Base64.encodeBase64String(mac.doFinal(source));
            return signature.equals(encodeResult);
        } catch (Exception e) {
            log.error("line signature validate exception.", e);
            return false;
        }
    }

Interface Prototype

Table 1 Interface prototype description

Method

POST

URL

https://{IP address}:{Port number}/social/on/line/{channelId}

{IP address}:{Port number} indicates the IP address and port number of the NSLB exposed externally.

{channelId} indicates the channel ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory or Not

Type

Default Value

Description

Content-Type

Yes

String

None

The value is fixed at application/json; charset=UTF-8.

X-Forwarded-For

Yes

String

None

IP address for sending messages.

x-line-signature

Yes

String

None

Request header signature verification.

Table 3 Request body parameter

Parameter

Mandatory or Not

Type

Default Value

Description

events

Yes

JSON array

None

Event data in events. For details, see Table 4.

Table 4 events parameters

Parameter

Mandatory or Not

Type

Default Value

Description

type

Yes

String

None

Message type.

mode

Yes

String

active

Message mode.

source

Yes

JSON object

None

Message source. For details, see Table 5.

message

Yes

JSON object

None

Specific message. For details, see Table 6.

Table 5 source parameters

Parameter

Mandatory or Not

Type

Default Value

Description

type

Yes

String

user

Message source.

userId

Yes

String

None

User ID.

Table 6 message parameters

Parameter

Mandatory or Not

Type

Default Value

Description

id

Yes

String

None

Unique code of a user message.

type

Yes

String

None

Message type. The value can be text, audio, image, video, or location.

latitude

No

BigDecimal

None

Longitude.

longitude

No

BigDecimal

None

Latitude.

text

No

String

None

Text message.

contentProvider

No

JSON object

None

Multimedia content provider. For details, see Table 7.

Table 7 contentProvider parameters

Parameter

Mandatory or Not

Type

Default Value

Description

type

Yes

String

None

Provider type.

originalContentUrl

Yes

String

None

Original multimedia URL.

previewImageUrl

No

String

None

URL of a thumbnail.

Response Parameters

None

Example

  • Request
    POST 
    /********************
    Accept: */*
    Host: 10.154.198.164
    Content-Type: application/json;charset=UTF-8
    Content-Length: 185
    {
    	"events": [
    		{
    			"type": "",
    			"mode": "active",
    			"source": 
    				{"type": "user",
    				"userId": "8615897042502"	
    				},
    			"message": {
    				"id":"asdwe145FFUfj",
    				"type": "TEXT",
    				"text": "hello"
    			}
    		}
    		]
    }