├── system.properties ├── lombok.config ├── .travis.yml ├── Procfile ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── line-bot-model ├── src │ ├── test │ │ ├── resources │ │ │ ├── richmenu │ │ │ │ ├── richmenu_id_response.json │ │ │ │ ├── richmenu_response.json │ │ │ │ ├── richmenu_request.json │ │ │ │ └── richmenu_list_response.json │ │ │ ├── user-profiles_member.json │ │ │ ├── error │ │ │ │ ├── error401.json │ │ │ │ └── error_with_detail.json │ │ │ ├── user-profiles.json │ │ │ └── callback │ │ │ │ ├── leave.json │ │ │ │ ├── unfollow.json │ │ │ │ ├── follow.json │ │ │ │ ├── join.json │ │ │ │ ├── image.json │ │ │ │ ├── beacon.json │ │ │ │ ├── postback.json │ │ │ │ ├── text-user.json │ │ │ │ ├── text-group.json │ │ │ │ ├── beacon_with_dm.json │ │ │ │ ├── sticker.json │ │ │ │ ├── file.json │ │ │ │ ├── location.json │ │ │ │ └── unknown.json │ │ └── java │ │ │ └── com │ │ │ └── linecorp │ │ │ └── bot │ │ │ └── model │ │ │ ├── testutil │ │ │ └── TestUtil.java │ │ │ ├── message │ │ │ ├── imagemap │ │ │ │ ├── MessageImagemapActionTest.java │ │ │ │ └── URIImagemapActionTest.java │ │ │ └── ImagemapMessageTest.java │ │ │ ├── event │ │ │ ├── beacon │ │ │ │ └── BeaconContentTest.java │ │ │ ├── MessageEventTest.java │ │ │ └── ReplyEventTest.java │ │ │ ├── error │ │ │ └── ErrorResponseTest.java │ │ │ └── profile │ │ │ └── ProfileResponseTest.java │ └── main │ │ └── java │ │ └── com │ │ └── linecorp │ │ └── bot │ │ └── model │ │ ├── richmenu │ │ ├── RichMenuIdResponse.java │ │ ├── RichMenuListResponse.java │ │ ├── RichMenuSize.java │ │ ├── RichMenuBounds.java │ │ ├── RichMenuArea.java │ │ ├── RichMenuCommonProperties.java │ │ ├── RichMenu.java │ │ └── RichMenuResponse.java │ │ ├── event │ │ ├── ReplyEvent.java │ │ ├── source │ │ │ ├── UnknownSource.java │ │ │ ├── UserSource.java │ │ │ ├── RoomSource.java │ │ │ ├── Source.java │ │ │ └── GroupSource.java │ │ ├── CallbackRequest.java │ │ ├── message │ │ │ ├── UnknownMessageContent.java │ │ │ ├── AudioMessageContent.java │ │ │ ├── ImageMessageContent.java │ │ │ ├── VideoMessageContent.java │ │ │ ├── TextMessageContent.java │ │ │ ├── FileMessageContent.java │ │ │ ├── StickerMessageContent.java │ │ │ ├── MessageContent.java │ │ │ └── LocationMessageContent.java │ │ ├── postback │ │ │ └── PostbackContent.java │ │ ├── LeaveEvent.java │ │ ├── UnfollowEvent.java │ │ ├── UnknownEvent.java │ │ ├── Event.java │ │ ├── JoinEvent.java │ │ ├── FollowEvent.java │ │ ├── BeaconEvent.java │ │ ├── MessageEvent.java │ │ ├── PostbackEvent.java │ │ └── beacon │ │ │ └── BeaconContentUtil.java │ │ ├── Multicast.java │ │ ├── message │ │ ├── ImageMessage.java │ │ ├── imagemap │ │ │ ├── ImagemapBaseSize.java │ │ │ ├── ImagemapArea.java │ │ │ ├── ImagemapAction.java │ │ │ ├── MessageImagemapAction.java │ │ │ └── URIImagemapAction.java │ │ ├── StickerMessage.java │ │ ├── TextMessage.java │ │ ├── AudioMessage.java │ │ ├── LocationMessage.java │ │ ├── template │ │ │ ├── Template.java │ │ │ ├── ImageCarouselTemplate.java │ │ │ ├── ConfirmTemplate.java │ │ │ ├── ImageCarouselColumn.java │ │ │ ├── CarouselTemplate.java │ │ │ └── CarouselColumn.java │ │ ├── TemplateMessage.java │ │ ├── VideoMessage.java │ │ ├── ImagemapMessage.java │ │ └── Message.java │ │ ├── error │ │ ├── ErrorDetail.java │ │ └── ErrorResponse.java │ │ ├── profile │ │ ├── MembersIdsResponse.java │ │ └── UserProfileResponse.java │ │ ├── response │ │ └── BotApiResponse.java │ │ ├── action │ │ ├── Action.java │ │ ├── URIAction.java │ │ ├── MessageAction.java │ │ └── PostbackAction.java │ │ ├── PushMessage.java │ │ └── ReplyMessage.java └── build.gradle ├── sample-spring-boot-echo ├── _assets │ ├── heroku.png │ ├── heroku-app-name.png │ ├── put-webhook-url.png │ └── line-bot-configuration.png ├── build.gradle ├── src │ └── main │ │ ├── resources │ │ └── application-template.yml │ │ └── java │ │ └── com │ │ └── example │ │ └── bot │ │ └── spring │ │ └── echo │ │ └── EchoApplication.java └── README.md ├── sample-spring-boot-kitchensink ├── src │ └── main │ │ ├── resources │ │ ├── static │ │ │ ├── rich │ │ │ │ ├── 240 │ │ │ │ ├── 300 │ │ │ │ ├── 460 │ │ │ │ ├── 700 │ │ │ │ └── 1040 │ │ │ └── buttons │ │ │ │ └── 1040.jpg │ │ └── application-template.yml │ │ └── java │ │ └── com │ │ └── example │ │ └── bot │ │ └── spring │ │ ├── KitchenSinkApplication.java │ │ └── KitchenSinkWebMvcConfigurer.java ├── build.gradle └── README.md ├── line-bot-spring-boot ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── spring.factories │ │ └── java │ │ │ └── com │ │ │ └── linecorp │ │ │ └── bot │ │ │ └── spring │ │ │ └── boot │ │ │ ├── annotation │ │ │ ├── LineBotMessages.java │ │ │ ├── EnableLineMessaging.java │ │ │ ├── LineMessageHandler.java │ │ │ └── EventMapping.java │ │ │ ├── LineBotWebMvcConfigurer.java │ │ │ ├── support │ │ │ └── LineBotServerArgumentProcessor.java │ │ │ └── BotPropertiesValidator.java │ └── test │ │ ├── resources │ │ └── callback-request.json │ │ └── java │ │ └── com │ │ └── linecorp │ │ └── bot │ │ └── spring │ │ └── boot │ │ └── test │ │ └── EventTestUtil.java └── build.gradle ├── line-bot-api-client ├── README.md ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── linecorp │ │ │ └── bot │ │ │ └── client │ │ │ ├── exception │ │ │ ├── NotFoundException.java │ │ │ ├── BadRequestException.java │ │ │ ├── ForbiddenException.java │ │ │ ├── LineServerException.java │ │ │ ├── UnauthorizedException.java │ │ │ ├── TooManyRequestsException.java │ │ │ ├── GeneralLineMessagingException.java │ │ │ └── LineMessagingException.java │ │ │ ├── ChannelTokenSupplier.java │ │ │ ├── FixedChannelTokenSupplier.java │ │ │ ├── MessageContentResponse.java │ │ │ ├── HeaderInterceptor.java │ │ │ └── LineSignatureValidator.java │ └── test │ │ └── java │ │ └── com │ │ └── linecorp │ │ └── bot │ │ └── client │ │ ├── LineMessagingClientImplRichMenuWiremockTest.java │ │ ├── FixedChannelTokenSupplierTest.java │ │ ├── LineSignatureValidatorTest.java │ │ ├── AbstractWiremockTest.java │ │ ├── HeaderInterceptorWireMockTest.java │ │ └── CallbackAdaptorTest.java └── build.gradle ├── app.json ├── .github └── ISSUE_TEMPLATE.md ├── line-bot-servlet ├── src │ ├── test │ │ └── resources │ │ │ └── callback-request.json │ └── main │ │ └── java │ │ └── com │ │ └── linecorp │ │ └── bot │ │ └── servlet │ │ └── LineBotCallbackException.java └── build.gradle ├── .gitignore ├── settings.gradle ├── CONTRIBUTING.md └── gradlew.bat /system.properties: -------------------------------------------------------------------------------- 1 | java.runtime.version=1.8 2 | -------------------------------------------------------------------------------- /lombok.config: -------------------------------------------------------------------------------- 1 | lombok.anyConstructor.suppressConstructorProperties = true 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | jdk: 4 | - oraclejdk8 5 | install: ./gradlew check 6 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: java $JAVA_OPTS -jar sample-spring-boot-echo/build/libs/sample-spring-boot-echo-*.jar --server.port=$PORT 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simple/line-bot-sdk-java/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/richmenu/richmenu_id_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "richMenuId": "richmenu-3c05e9f99d5bee8b21b4c3e0e09d3eec" 3 | } 4 | -------------------------------------------------------------------------------- /sample-spring-boot-echo/_assets/heroku.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simple/line-bot-sdk-java/master/sample-spring-boot-echo/_assets/heroku.png -------------------------------------------------------------------------------- /sample-spring-boot-echo/_assets/heroku-app-name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simple/line-bot-sdk-java/master/sample-spring-boot-echo/_assets/heroku-app-name.png -------------------------------------------------------------------------------- /sample-spring-boot-echo/_assets/put-webhook-url.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simple/line-bot-sdk-java/master/sample-spring-boot-echo/_assets/put-webhook-url.png -------------------------------------------------------------------------------- /sample-spring-boot-echo/_assets/line-bot-configuration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simple/line-bot-sdk-java/master/sample-spring-boot-echo/_assets/line-bot-configuration.png -------------------------------------------------------------------------------- /sample-spring-boot-kitchensink/src/main/resources/static/rich/240: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simple/line-bot-sdk-java/master/sample-spring-boot-kitchensink/src/main/resources/static/rich/240 -------------------------------------------------------------------------------- /sample-spring-boot-kitchensink/src/main/resources/static/rich/300: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simple/line-bot-sdk-java/master/sample-spring-boot-kitchensink/src/main/resources/static/rich/300 -------------------------------------------------------------------------------- /sample-spring-boot-kitchensink/src/main/resources/static/rich/460: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simple/line-bot-sdk-java/master/sample-spring-boot-kitchensink/src/main/resources/static/rich/460 -------------------------------------------------------------------------------- /sample-spring-boot-kitchensink/src/main/resources/static/rich/700: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simple/line-bot-sdk-java/master/sample-spring-boot-kitchensink/src/main/resources/static/rich/700 -------------------------------------------------------------------------------- /sample-spring-boot-kitchensink/src/main/resources/static/rich/1040: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simple/line-bot-sdk-java/master/sample-spring-boot-kitchensink/src/main/resources/static/rich/1040 -------------------------------------------------------------------------------- /sample-spring-boot-kitchensink/src/main/resources/static/buttons/1040.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simple/line-bot-sdk-java/master/sample-spring-boot-kitchensink/src/main/resources/static/buttons/1040.jpg -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/user-profiles_member.json: -------------------------------------------------------------------------------- 1 | { 2 | "displayName": "Tester", 3 | "userId": "Uc6a5e7b3d4d08c33dd8d530fb3c02762", 4 | "pictureUrl": "https://example.com/picture.png" 5 | } 6 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/error/error401.json: -------------------------------------------------------------------------------- 1 | { 2 | "message": "Authentication failed due to the following reason: invalid token. Confirm that the access token in the authorization header is valid." 3 | } 4 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/user-profiles.json: -------------------------------------------------------------------------------- 1 | { 2 | "displayName": "Tester", 3 | "userId": "Uc6a5e7b3d4d08c33dd8d530fb3c02762", 4 | "pictureUrl": "https://example.com/picture.png", 5 | "statusMessage": "Movie" 6 | } 7 | -------------------------------------------------------------------------------- /line-bot-spring-boot/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.linecorp.bot.spring.boot.LineBotAutoConfiguration,com.linecorp.bot.spring.boot.LineBotWebMvcConfigurer 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip 6 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/leave.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "type": "leave", 5 | "timestamp": 1462629479859, 6 | "source": { 7 | "type": "group", 8 | "groupId": "cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 9 | } 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/unfollow.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "type": "unfollow", 5 | "timestamp": 1462629479859, 6 | "source": { 7 | "type": "user", 8 | "userId": "u206d25c2ea6bd87c17655609a1c37cb8" 9 | } 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/richmenu/richmenu_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "richMenuId": "richmenu-f85ab95699420f1c9330f22bb4f489e8", 3 | "size": { 4 | "width": 2500, 5 | "height": 843 6 | }, 7 | "selected": true, 8 | "name": "NAME", 9 | "chatBarText": "CHAT_BAR_TEXT", 10 | "areas": [ ] 11 | } 12 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/follow.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "follow", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "user", 9 | "userId": "u206d25c2ea6bd87c17655609a1c37cb8" 10 | } 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/join.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "join", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "group", 9 | "groupId": "cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 10 | } 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /line-bot-api-client/README.md: -------------------------------------------------------------------------------- 1 | # line-bot-api-client 2 | 3 | LINE Messaging API client for Java 8 or later. 4 | 5 | ## Synopsis 6 | 7 | ```java 8 | LineMessagingService client = LineMessagingServiceBuilder 9 | .create("YOUR_CHANNEL_TOKEN") 10 | .build(); 11 | ``` 12 | 13 | ## Description 14 | 15 | This module provides an API client for the LINE Messaging API. 16 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/error/error_with_detail.json: -------------------------------------------------------------------------------- 1 | { 2 | "message": "The request body has 2 error(s)", 3 | "details": [ 4 | { "message": "May not be empty", "property": "messages[0].text" }, 5 | { 6 | "message": "Must be one of the following values: [text, image, video, audio, location, sticker, richmessage, template, imagemap]", 7 | "property": "messages[1].type" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/richmenu/RichMenuIdResponse.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model.richmenu; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | 5 | import lombok.Value; 6 | 7 | @Value 8 | public class RichMenuIdResponse { 9 | String richMenuId; 10 | 11 | @JsonCreator 12 | public RichMenuIdResponse(final String richMenuId) { 13 | this.richMenuId = richMenuId; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/image.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "message", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "user", 9 | "userId": "u206d25c2ea6bd87c17655609a1c37cb8" 10 | }, 11 | "message": { 12 | "id": "325708", 13 | "type": "image" 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/beacon.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "beacon", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "user", 9 | "userId": "U012345678901234567890123456789ab" 10 | }, 11 | "beacon": { 12 | "hwid": "374591320", 13 | "type": "enter" 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/postback.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "postback", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "user", 9 | "userId": "u206d25c2ea6bd87c17655609a1c37cb8" 10 | }, 11 | "postback": { 12 | "data": "action=buyItem&itemId=123123&color=red", 13 | "params": { } 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/text-user.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "message", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "user", 9 | "userId": "u206d25c2ea6bd87c17655609a1c37cb8" 10 | }, 11 | "message": { 12 | "id": "325708", 13 | "type": "text", 14 | "text": "Hello, world" 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/text-group.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "message", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "group", 9 | "groupId": "u206d25c2ea6bd87c17655609a1c37cb8" 10 | }, 11 | "message": { 12 | "id": "325708", 13 | "type": "text", 14 | "text": "Hello, world" 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/beacon_with_dm.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "type": "beacon", 5 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 6 | "source": { 7 | "userId": "U012345678901234567890123456789ab", 8 | "type": "user" 9 | }, 10 | "timestamp": 1492992000000, 11 | "beacon": { 12 | "hwid": "374591320", 13 | "dm": "1234567890abcdef", 14 | "type": "enter" 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/sticker.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "message", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "user", 9 | "userId": "u206d25c2ea6bd87c17655609a1c37cb8" 10 | }, 11 | "message": { 12 | "id": "325708", 13 | "type": "sticker", 14 | "packageId": "1", 15 | "stickerId": "1" 16 | } 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/file.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "message", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "user", 9 | "userId": "u206d25c2ea6bd87c17655609a1c37cb8" 10 | }, 11 | "message": { 12 | "id": "325708", 13 | "type": "file", 14 | "fileName": "sample.pdf", 15 | "fileSize": 22016 16 | } 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/richmenu/richmenu_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "size": { 3 | "width": 2500, 4 | "height": 1686 5 | }, 6 | "selected": false, 7 | "name": "Nice richmenu", 8 | "chatBarText": "Tap here", 9 | "areas": [ 10 | { 11 | "bounds": { 12 | "x": 0, 13 | "y": 0, 14 | "width": 2500, 15 | "height": 1686 16 | }, 17 | "action": { 18 | "type": "postback", 19 | "data": "action=buy&itemid=123" 20 | } 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/exception/NotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.client.exception; 2 | 3 | import com.linecorp.bot.model.error.ErrorResponse; 4 | 5 | public class NotFoundException extends LineMessagingException { 6 | private static final long serialVersionUID = SERIAL_VERSION_UID; 7 | 8 | public NotFoundException( 9 | final String message, 10 | final ErrorResponse errorResponse) { 11 | super(message, errorResponse, null); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/ReplyEvent.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model.event; 2 | 3 | import com.linecorp.bot.model.ReplyMessage; 4 | 5 | /** 6 | * Interface for reply support. 7 | * 8 | * @see Event 9 | */ 10 | public interface ReplyEvent { 11 | /** 12 | * Token for replying to this event. 13 | * 14 | * @see ReplyMessage 15 | * @see //devdocs.line.me/#reply-message > Request Body 16 | */ 17 | String getReplyToken(); 18 | } 19 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "echo bot - LINE Messaging API", 3 | "description": "This is a sample application for the LINE Messaging API", 4 | "keywords": ["chatbot", "line", "java"], 5 | "env": { 6 | "LINE_BOT_CHANNEL_TOKEN": { 7 | "description": "LINE bot Channel access token from the Channel Console", 8 | "required": true 9 | }, 10 | "LINE_BOT_CHANNEL_SECRET": { 11 | "description": "LINE bot Channel secret from the Channel Console", 12 | "required": true 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/richmenu/RichMenuListResponse.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model.richmenu; 2 | 3 | import java.util.List; 4 | 5 | import com.fasterxml.jackson.annotation.JsonCreator; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | import lombok.Value; 9 | 10 | @Value 11 | public class RichMenuListResponse { 12 | @JsonProperty("richmenus") 13 | List richMenus; 14 | 15 | @JsonCreator 16 | public RichMenuListResponse(final List richMenus) { 17 | this.richMenus = richMenus; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/location.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "message", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "user", 9 | "userId": "u206d25c2ea6bd87c17655609a1c37cb8" 10 | }, 11 | "message": { 12 | "id": "325708", 13 | "type": "location", 14 | "title": "hello", 15 | "address": "〒150-0002 東京都渋谷区渋谷2丁目21−1", 16 | "latitude": 35.65910807942215, 17 | "longitude": 139.70372892916203 18 | } 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Do this before creating an issue 2 | 3 | - Check our [developer documentation](https://developers.line.me/en/docs/) and [FAQ](https://developers.line.me/en/faq/messaging-api/) page for more information on LINE bots and the Messaging API 4 | - Make sure your issue is **related to** the LINE Bot SDK. For general questions or issues about LINE bots, create an issue on the [LINE Platform feedback](https://github.com/line/line-platform-feedback) repository. Note that we don't provide technical support. 5 | 6 | ## When creating an issue 7 | 8 | - Provide detailed information about the issue you had with the SDK 9 | - Provide logs if possible 10 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/richmenu/richmenu_list_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "richmenus": [ 3 | { 4 | "richMenuId": "{richMenuId}", 5 | "size": { 6 | "width": 2500, 7 | "height": 1686 8 | }, 9 | "selected": false, 10 | "name": "NAME", 11 | "chatBarText": "CHAT_BAR_TEXT", 12 | "areas": [ 13 | { 14 | "bounds": { 15 | "x": 0, 16 | "y": 0, 17 | "width": 2500, 18 | "height": 1686 19 | }, 20 | "action": { 21 | "type": "postback", 22 | "data": "action=buy&itemid=123" 23 | } 24 | } 25 | ] 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /line-bot-model/src/test/resources/callback/unknown.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "greatNewFeature", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "user", 9 | "userId": "U012345678901234567890123456789ab" 10 | } 11 | }, 12 | { 13 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 14 | "type": "message", 15 | "timestamp": 1462629479859, 16 | "source": { 17 | "type": "unknownunknownuknown" 18 | }, 19 | "message": { 20 | "id": "325708", 21 | "type": "unknownunknownuknown", 22 | "unknown": "blah blah" 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/richmenu/RichMenuSize.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model.richmenu; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | 5 | import lombok.Value; 6 | 7 | @Value 8 | public class RichMenuSize { 9 | public static final RichMenuSize FULL = new RichMenuSize(2500, 1686); 10 | public static final RichMenuSize HALF = new RichMenuSize(2500, 843); 11 | 12 | /** Width of the rich menu. Must be 2500. */ 13 | int width; 14 | /** Height of the rich menu. Possible values: 1686 or 843. */ 15 | int height; 16 | 17 | @JsonCreator 18 | public RichMenuSize(final int width, final int height) { 19 | this.width = width; 20 | this.height = height; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /line-bot-servlet/src/test/resources/callback-request.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "message", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "user", 9 | "userId": "u206d25c2ea6bd87c17655609a1c37cb8" 10 | }, 11 | "message": { 12 | "id": "325708", 13 | "type": "text", 14 | "text": "Hello, world" 15 | } 16 | }, 17 | { 18 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 19 | "type": "follow", 20 | "timestamp": 1462629479859, 21 | "source": { 22 | "type": "user", 23 | "userId": "u206d25c2ea6bd87c17655609a1c37cb8" 24 | } 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /line-bot-spring-boot/src/test/resources/callback-request.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 5 | "type": "message", 6 | "timestamp": 1462629479859, 7 | "source": { 8 | "type": "user", 9 | "userId": "u206d25c2ea6bd87c17655609a1c37cb8" 10 | }, 11 | "message": { 12 | "id": "325708", 13 | "type": "text", 14 | "text": "Hello, world" 15 | } 16 | }, 17 | { 18 | "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", 19 | "type": "follow", 20 | "timestamp": 1462629479859, 21 | "source": { 22 | "type": "user", 23 | "userId": "u206d25c2ea6bd87c17655609a1c37cb8" 24 | } 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /line-bot-spring-boot/src/test/java/com/linecorp/bot/spring/boot/test/EventTestUtil.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.spring.boot.test; 2 | 3 | import java.time.Instant; 4 | 5 | import com.linecorp.bot.model.event.MessageEvent; 6 | import com.linecorp.bot.model.event.message.TextMessageContent; 7 | import com.linecorp.bot.model.event.source.UserSource; 8 | 9 | import lombok.experimental.UtilityClass; 10 | 11 | @UtilityClass 12 | public class EventTestUtil { 13 | public static MessageEvent createTextMessage(final String text) { 14 | return new MessageEvent<>("replyToken", new UserSource("userId"), 15 | new TextMessageContent("id", text), 16 | Instant.parse("2016-11-19T00:00:00.000Z")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/richmenu/RichMenuBounds.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model.richmenu; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | 5 | import lombok.Value; 6 | 7 | @Value 8 | public class RichMenuBounds { 9 | /** Horizontal position relative to the top-left corner of the area. */ 10 | int x; 11 | 12 | /** Vertical position relative to the top-left corner of the area. */ 13 | int y; 14 | 15 | /** Width of the area. */ 16 | int width; 17 | 18 | /** Height of the area. */ 19 | int height; 20 | 21 | @JsonCreator 22 | public RichMenuBounds(final int x, final int y, final int width, final int height) { 23 | this.x = x; 24 | this.y = y; 25 | this.width = width; 26 | this.height = height; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/richmenu/RichMenuArea.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model.richmenu; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | 5 | import com.linecorp.bot.model.action.Action; 6 | 7 | import lombok.Value; 8 | 9 | @Value 10 | public class RichMenuArea { 11 | /** 12 | * Object describing the boundaries of the area in pixels. 13 | */ 14 | RichMenuBounds bounds; 15 | 16 | /** 17 | * Action performed when the area is tapped. See {@link Action} objects. 18 | * 19 | * Note: The label field is not supported for actions in rich menus. 20 | */ 21 | Action action; 22 | 23 | @JsonCreator 24 | public RichMenuArea(final RichMenuBounds bounds, final Action action) { 25 | this.bounds = bounds; 26 | this.action = action; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample-spring-boot-echo/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | apply plugin: 'org.springframework.boot' 18 | 19 | dependencies { 20 | compile project(':line-bot-spring-boot') 21 | } 22 | -------------------------------------------------------------------------------- /sample-spring-boot-kitchensink/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | apply plugin: 'org.springframework.boot' 18 | 19 | dependencies { 20 | compile project(':line-bot-spring-boot') 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build output 2 | target/ 3 | build/ 4 | out/ 5 | 6 | # gradle 7 | /.gradle/ 8 | 9 | # Mobile Tools for Java (J2ME) 10 | .mtj.tmp/ 11 | 12 | # Package Files # 13 | *.jar 14 | *.war 15 | *.ear 16 | 17 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 18 | hs_err_pid* 19 | 20 | # IntelliJ 21 | .idea 22 | *.iml 23 | *.iws 24 | *.ipr 25 | *.ids 26 | *.orig 27 | 28 | # Eclipse 29 | *.pydevproject 30 | .project 31 | .metadata 32 | /bin/** 33 | /tmp/** 34 | /tmp/**/* 35 | *.tmp 36 | *.bak 37 | *.swp 38 | *~.nib 39 | local.properties 40 | .classpath 41 | .settings/** 42 | .loadpath 43 | /src/main/resources/rebel.xml 44 | 45 | # External tool builders 46 | .externalToolBuilders/** 47 | 48 | # Locally stored "Eclipse launch configurations" 49 | *.launch 50 | 51 | # CDT-specific 52 | .cproject 53 | 54 | # PDT-specific 55 | .buildpath 56 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'line-bot-api-client' 2 | include 'line-bot-model' 3 | include 'line-bot-servlet' 4 | include 'line-bot-spring-boot' 5 | 6 | /* 7 | * Copyright 2018 LINE Corporation 8 | * 9 | * LINE Corporation licenses this file to you under the Apache License, 10 | * version 2.0 (the "License"); you may not use this file except in compliance 11 | * with the License. You may obtain a copy of the License at: 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 18 | * License for the specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | // samples 23 | include 'sample-spring-boot-kitchensink' 24 | include 'sample-spring-boot-echo' 25 | 26 | -------------------------------------------------------------------------------- /sample-spring-boot-kitchensink/README.md: -------------------------------------------------------------------------------- 1 | # sample-spring-boot-kitchensink 2 | 3 | ## What is this? 4 | 5 | This is a full-featured sample application for the LINE Messaging API. 6 | 7 | ## Usage 8 | 9 | Run this sample bot using Gradle. 10 | 11 | ../gradlew bootRun -Dline.bot.channelToken=YOUR_CHANNEL_TOKEN \ 12 | -Dline.bot.channelSecret=YOUR_CHANNEL_SECRET 13 | 14 | or if you finished create `src/main/resources/application.yml` file based on `src/main/resources/application-template.yml`. You can start configured web server just hitting 15 | 16 | ../gradlew bootRun 17 | 18 | You need to pass the following options. 19 | 20 | * line.bot.channelToken: Your Channel access token 21 | * line.bot.channelSecret: Your Channel secret 22 | 23 | For more information about configuration way, refer [Spring Boot Reference - 24. Externalized Configuration](https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html). 24 | -------------------------------------------------------------------------------- /line-bot-servlet/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | dependencies { 18 | compile project(':line-bot-api-client') 19 | compile 'com.fasterxml.jackson.core:jackson-databind' 20 | compile 'com.google.guava:guava' 21 | 22 | optional 'javax.servlet:javax.servlet-api' 23 | optional 'org.slf4j:slf4j-api' 24 | } 25 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to contribute to LINE Bot SDK for Java project 2 | 3 | First of all, thank you so much for taking your time to contribute! LINE Bot SDK for Java is not very different from any other open 4 | source projects you are aware of. It will be amazing if you could help us by doing any of the following: 5 | 6 | - File an issue in [the issue tracker](https://github.com/line/line-bot-sdk-java/issues) to report bugs and propose new features and 7 | improvements. 8 | - Ask a question using [the issue tracker](https://github.com/line/line-bot-sdk-java/issues). 9 | - Contribute your work by sending [a pull request](https://github.com/line/line-bot-sdk-java/pulls). 10 | 11 | ### Contributor license agreement 12 | 13 | If you are sending a pull request and it's a non-trivial change beyond fixing typos, please make sure to sign 14 | [the ICLA (individual contributor license agreement)](https://feedback.line.me/enquete/public/919-h9Yqmr1u). Please 15 | contact us if you need the CCLA (corporate contributor license agreement). 16 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/Multicast.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import java.util.Set; 6 | 7 | import com.linecorp.bot.model.message.Message; 8 | 9 | import lombok.AllArgsConstructor; 10 | import lombok.Value; 11 | 12 | /** 13 | * Send messages to multiple users, groups, and rooms at any time. 14 | */ 15 | @Value 16 | @AllArgsConstructor 17 | public class Multicast { 18 | /** 19 | * IDs of the receivers.
20 | * Max: 150 21 | * 22 | *

INFO: Use IDs returned via the webhook event of source users. IDs of groups or rooms cannot be used.

23 | */ 24 | private final Set to; 25 | 26 | /** 27 | * List of Message objects.
28 | * Max: 5 29 | */ 30 | private final List messages; 31 | 32 | public Multicast(final Set to, final Message message) { 33 | this.to = to; 34 | this.messages = Collections.singletonList(message); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /line-bot-servlet/src/main/java/com/linecorp/bot/servlet/LineBotCallbackException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.servlet; 18 | 19 | public class LineBotCallbackException extends Exception { 20 | private static final long serialVersionUID = -950894346433317253L; 21 | 22 | public LineBotCallbackException(String message) { 23 | super(message); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /line-bot-spring-boot/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | dependencies { 18 | compile project(':line-bot-api-client') 19 | compile project(':line-bot-model') 20 | compile project(':line-bot-servlet') 21 | compile 'org.springframework.boot:spring-boot-autoconfigure' 22 | compile 'org.springframework.boot:spring-boot-starter-web' 23 | 24 | optional 'javax.validation:validation-api' 25 | } 26 | -------------------------------------------------------------------------------- /line-bot-model/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | dependencies { 18 | compile 'com.fasterxml.jackson.core:jackson-core' 19 | compile 'com.fasterxml.jackson.core:jackson-databind' 20 | compile 'com.fasterxml.jackson.core:jackson-annotations' 21 | 22 | testCompile 'com.fasterxml.jackson.module:jackson-module-parameter-names' 23 | testCompile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' 24 | } 25 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/ChannelTokenSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client; 18 | 19 | import java.util.function.Supplier; 20 | 21 | /** 22 | * Special {@link Supplier} for Channel Access Token. 23 | * 24 | * You can implement it to return same channel tokens. 25 | * Or refresh tokens internally. 26 | */ 27 | @FunctionalInterface 28 | public interface ChannelTokenSupplier extends Supplier { 29 | } 30 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/ImageMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonTypeName; 20 | 21 | import lombok.Value; 22 | 23 | /** 24 | * Image message 25 | */ 26 | @Value 27 | @JsonTypeName("image") 28 | public class ImageMessage implements Message { 29 | private final String originalContentUrl; 30 | private final String previewImageUrl; 31 | } 32 | -------------------------------------------------------------------------------- /line-bot-spring-boot/src/main/java/com/linecorp/bot/spring/boot/annotation/LineBotMessages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.spring.boot.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @Target(ElementType.PARAMETER) 26 | public @interface LineBotMessages { 27 | } 28 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/source/UnknownSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.source; 18 | 19 | import lombok.Value; 20 | 21 | /** 22 | * Fallback source type for {@link Source}. 23 | */ 24 | @Value 25 | public class UnknownSource implements Source { 26 | @Override 27 | public String getUserId() { 28 | return null; 29 | } 30 | 31 | @Override 32 | public String getSenderId() { 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/richmenu/RichMenuCommonProperties.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model.richmenu; 2 | 3 | import java.util.List; 4 | 5 | public interface RichMenuCommonProperties { 6 | /** 7 | * {@link RichMenuSize} object which contains the width and height of the rich menu displayed in the chat. 8 | * 9 | *

Rich menu images must be one of the following sizes: 2500x1686, 2500x843. */ 10 | RichMenuSize getSize(); 11 | 12 | /** true to display the rich menu by default. Otherwise, false. */ 13 | boolean isSelected(); 14 | 15 | /** 16 | * Name of the rich menu. This value can be used to help manage your rich menus and is not displayed to users. 17 | * 18 | *

Maximum of 300 characters. 19 | */ 20 | String getName(); 21 | 22 | /** 23 | * Text displayed in the chat bar. Maximum of 14 characters. 24 | */ 25 | String getChatBarText(); 26 | 27 | /** 28 | * Array of {@link RichMenuArea} objects which define the coordinates and size of tappable areas. 29 | * 30 | *

Maximum of 20 area objects. 31 | */ 32 | List getAreas(); 33 | } 34 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/imagemap/ImagemapBaseSize.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.imagemap; 18 | 19 | import lombok.Value; 20 | 21 | /** 22 | * Size of base image. 23 | */ 24 | @Value 25 | public class ImagemapBaseSize { 26 | /** 27 | * Width of base image(Set to 1040px) 28 | */ 29 | private final int height; 30 | 31 | /** 32 | * Height of base image(set to the height that coresponds to a width of 1040px) 33 | */ 34 | private final int width; 35 | } 36 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/exception/BadRequestException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client.exception; 18 | 19 | import com.linecorp.bot.model.error.ErrorResponse; 20 | 21 | public class BadRequestException extends LineMessagingException { 22 | private static final long serialVersionUID = SERIAL_VERSION_UID; 23 | 24 | public BadRequestException( 25 | final String message, 26 | final ErrorResponse errorResponse) { 27 | super(message, errorResponse, null); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/exception/ForbiddenException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client.exception; 18 | 19 | import com.linecorp.bot.model.error.ErrorResponse; 20 | 21 | public class ForbiddenException extends LineMessagingException { 22 | private static final long serialVersionUID = SERIAL_VERSION_UID; 23 | 24 | public ForbiddenException( 25 | final String message, 26 | final ErrorResponse errorResponse) { 27 | super(message, errorResponse, null); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/exception/LineServerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client.exception; 18 | 19 | import com.linecorp.bot.model.error.ErrorResponse; 20 | 21 | public class LineServerException extends LineMessagingException { 22 | private static final long serialVersionUID = SERIAL_VERSION_UID; 23 | 24 | public LineServerException( 25 | final String message, 26 | final ErrorResponse errorResponse) { 27 | super(message, errorResponse, null); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sample-spring-boot-echo/src/main/resources/application-template.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2018 LINE Corporation 3 | # 4 | # LINE Corporation licenses this file to you under the Apache License, 5 | # version 2.0 (the "License"); you may not use this file except in compliance 6 | # with the License. You may obtain a copy of the License at: 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | # License for the specific language governing permissions and limitations 14 | # under the License. 15 | 16 | This is tempalte file for configuration. 17 | Please copy as `application.yml` and change your value. 18 | 19 | line.bot: 20 | channel-token: 'Put Your Channel Token Here.' 21 | channel-secret: 'Put Your Channel Secret Here.' 22 | handler.path: /callback 23 | 24 | # To remove Client wire logs. Please comment out following lines. 25 | # See: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html 26 | # 27 | #logging.level: 28 | # com.linecorp.bot.client.wire: INFO 29 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/exception/UnauthorizedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client.exception; 18 | 19 | import com.linecorp.bot.model.error.ErrorResponse; 20 | 21 | public class UnauthorizedException extends LineMessagingException { 22 | private static final long serialVersionUID = SERIAL_VERSION_UID; 23 | 24 | public UnauthorizedException( 25 | final String message, 26 | final ErrorResponse errorResponse) { 27 | super(message, errorResponse, null); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sample-spring-boot-kitchensink/src/main/resources/application-template.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2018 LINE Corporation 3 | # 4 | # LINE Corporation licenses this file to you under the Apache License, 5 | # version 2.0 (the "License"); you may not use this file except in compliance 6 | # with the License. You may obtain a copy of the License at: 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | # License for the specific language governing permissions and limitations 14 | # under the License. 15 | 16 | This is tempalte file for configuration. 17 | Please copy as `application.yml` and change your value. 18 | 19 | line.bot: 20 | channel-token: 'Put Your Channel Token Here.' 21 | channel-secret: 'Put Your Channel Secret Here.' 22 | handler.path: /callback 23 | 24 | # To remove Client wire logs. Please comment out following lines. 25 | # See: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html 26 | # 27 | #logging.level: 28 | # com.linecorp.bot.client.wire: INFO 29 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/exception/TooManyRequestsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client.exception; 18 | 19 | import com.linecorp.bot.model.error.ErrorResponse; 20 | 21 | public class TooManyRequestsException extends LineMessagingException { 22 | private static final long serialVersionUID = SERIAL_VERSION_UID; 23 | 24 | public TooManyRequestsException( 25 | final String message, 26 | final ErrorResponse errorResponse) { 27 | super(message, errorResponse, null); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /line-bot-api-client/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | dependencies { 18 | compile project(':line-bot-model') 19 | compile 'com.fasterxml.jackson.core:jackson-core' 20 | compile 'com.fasterxml.jackson.core:jackson-databind' 21 | compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' 22 | compile 'com.fasterxml.jackson.module:jackson-module-parameter-names' 23 | compile 'com.squareup.okhttp3:logging-interceptor' 24 | compile 'com.squareup.retrofit2:converter-jackson' 25 | compile 'com.squareup.retrofit2:retrofit' 26 | compile 'org.slf4j:slf4j-api' 27 | } 28 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/CallbackRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event; 18 | 19 | import java.util.List; 20 | 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | import lombok.Value; 24 | 25 | /** 26 | * Request object for webhook. 27 | */ 28 | @Value 29 | public class CallbackRequest { 30 | /** 31 | * List of events. 32 | */ 33 | private final List events; 34 | 35 | public CallbackRequest(@JsonProperty("events") List events) { 36 | this.events = events; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/richmenu/RichMenu.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model.richmenu; 2 | 3 | import java.util.List; 4 | 5 | import lombok.Builder; 6 | import lombok.Value; 7 | 8 | @Value 9 | @Builder(toBuilder = true) 10 | public class RichMenu implements RichMenuCommonProperties { 11 | /** 12 | * {@link RichMenuSize} object which contains the width and height of the rich menu displayed in the chat. 13 | * 14 | *

Rich menu images must be one of the following sizes: 2500x1686, 2500x843. 15 | */ 16 | RichMenuSize size; 17 | 18 | /** true to display the rich menu by default. Otherwise, false. */ 19 | boolean selected; 20 | 21 | /** 22 | * Name of the rich menu. This value can be used to help manage your rich menus and is not displayed to users. 23 | * 24 | *

Maximum of 300 characters. 25 | */ 26 | String name; 27 | 28 | /** 29 | * Text displayed in the chat bar. 30 | * 31 | *

Maximum of 14 characters. 32 | */ 33 | String chatBarText; 34 | 35 | /** 36 | * Array of {@link RichMenuArea} objects which define the coordinates and size of tappable areas. 37 | * 38 | *

Maximum of 20 area objects. 39 | */ 40 | List areas; 41 | } 42 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/StickerMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonTypeName; 20 | 21 | import lombok.NonNull; 22 | import lombok.Value; 23 | 24 | /** 25 | * Sticker message 26 | */ 27 | @Value 28 | @JsonTypeName("sticker") 29 | public class StickerMessage implements Message { 30 | /** 31 | * Package ID 32 | */ 33 | @NonNull 34 | private final String packageId; 35 | 36 | /** 37 | * Sticker ID 38 | */ 39 | @NonNull 40 | private final String stickerId; 41 | } 42 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/error/ErrorDetail.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.error; 18 | 19 | import com.fasterxml.jackson.annotation.JsonProperty; 20 | 21 | import lombok.Value; 22 | 23 | @Value 24 | public class ErrorDetail { 25 | /** Details of the error */ 26 | String message; 27 | 28 | /** Position of the error occurred */ 29 | String property; 30 | 31 | public ErrorDetail( 32 | @JsonProperty("message") String message, 33 | @JsonProperty("property") String property) { 34 | this.message = message; 35 | this.property = property; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/FixedChannelTokenSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client; 18 | 19 | import lombok.AllArgsConstructor; 20 | import lombok.NonNull; 21 | import lombok.ToString; 22 | 23 | /** 24 | * Implementation of {@link ChannelTokenSupplier} which always return fixed channel token. 25 | */ 26 | @AllArgsConstructor(staticName = "of") 27 | @ToString 28 | public final class FixedChannelTokenSupplier implements ChannelTokenSupplier { 29 | @NonNull 30 | private final String channelToken; 31 | 32 | @Override 33 | public String get() { 34 | return channelToken; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/message/UnknownMessageContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | 22 | import lombok.Value; 23 | 24 | /** 25 | * Fallback message content type for {@link MessageContent}. 26 | */ 27 | @Value 28 | public class UnknownMessageContent implements MessageContent { 29 | private final String id; 30 | 31 | @JsonCreator 32 | public UnknownMessageContent( 33 | @JsonProperty("id") String id) { 34 | this.id = id; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/TextMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonTypeName; 21 | 22 | import lombok.Value; 23 | 24 | @Value 25 | @JsonTypeName("text") 26 | public class TextMessage implements Message { 27 | private final String text; 28 | 29 | @JsonCreator 30 | // Constructor which has only one argument needs Jackson Annotation. 31 | // see MessageJsonReconstructionTest for detail. 32 | public TextMessage(final String text) { 33 | this.text = text; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/exception/GeneralLineMessagingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client.exception; 18 | 19 | import com.linecorp.bot.model.error.ErrorResponse; 20 | 21 | /** 22 | * General exceptions both in api server and SDK internal exceptions. 23 | */ 24 | public class GeneralLineMessagingException extends LineMessagingException { 25 | private static final long serialVersionUID = SERIAL_VERSION_UID; 26 | 27 | public GeneralLineMessagingException( 28 | final String message, final ErrorResponse errorResponse, final Throwable cause) { 29 | super(message, errorResponse, cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/message/AudioMessageContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.annotation.JsonTypeName; 22 | 23 | import lombok.Value; 24 | 25 | /** 26 | * Message content for audio type. 27 | */ 28 | @Value 29 | @JsonTypeName("audio") 30 | public class AudioMessageContent implements MessageContent { 31 | private final String id; 32 | 33 | @JsonCreator 34 | public AudioMessageContent(@JsonProperty("id") String id) { 35 | this.id = id; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/message/ImageMessageContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.annotation.JsonTypeName; 22 | 23 | import lombok.Value; 24 | 25 | /** 26 | * Message content for image type. 27 | */ 28 | @Value 29 | @JsonTypeName("image") 30 | public class ImageMessageContent implements MessageContent { 31 | private final String id; 32 | 33 | @JsonCreator 34 | public ImageMessageContent(@JsonProperty("id") String id) { 35 | this.id = id; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/source/UserSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.source; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.annotation.JsonTypeName; 22 | 23 | import lombok.Value; 24 | 25 | @Value 26 | @JsonTypeName("user") 27 | public class UserSource implements Source { 28 | private final String userId; 29 | 30 | @JsonCreator 31 | public UserSource(@JsonProperty("userId") String userId) { 32 | this.userId = userId; 33 | } 34 | 35 | @Override 36 | public String getSenderId() { 37 | return userId; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/AudioMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonTypeName; 20 | 21 | import lombok.Value; 22 | 23 | @Value 24 | @JsonTypeName("audio") 25 | public class AudioMessage implements Message { 26 | /** 27 | * URL of audio file 28 | *

    29 | *
  • HTTPS
  • 30 | *
  • m4a
  • 31 | *
  • Less than 1 minute
  • 32 | *
  • Max 10 MB
  • 33 | *
34 | */ 35 | private final String originalContentUrl; 36 | 37 | /** 38 | * Length of audio file (milliseconds) 39 | */ 40 | private final Integer duration; 41 | } 42 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/profile/MembersIdsResponse.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model.profile; 2 | 3 | import static java.util.Objects.requireNonNull; 4 | 5 | import java.util.List; 6 | import java.util.Optional; 7 | 8 | import com.fasterxml.jackson.annotation.JsonCreator; 9 | import com.fasterxml.jackson.annotation.JsonProperty; 10 | 11 | import lombok.Value; 12 | 13 | /** 14 | * @see //devdocs.line.me#get-group-room-member-ids 15 | */ 16 | @Value 17 | public class MembersIdsResponse { 18 | /** 19 | * List of user IDs of the members in the group or room. 20 | * 21 | *

Max: 100 user IDs 22 | */ 23 | List memberIds; 24 | 25 | String next; 26 | 27 | @JsonCreator 28 | public MembersIdsResponse( 29 | @JsonProperty("memberIds") final List memberIds, 30 | @JsonProperty("next") final String next) { 31 | this.memberIds = requireNonNull(memberIds, "memberIds is null"); 32 | this.next = next; 33 | } 34 | 35 | /** 36 | * Parameter to get continue member ids in next API call. a.k.a continuationToken 37 | * 38 | *

Returned if and only if there are more user IDs remaining. 39 | */ 40 | public Optional getNext() { 41 | return Optional.ofNullable(next); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /line-bot-spring-boot/src/main/java/com/linecorp/bot/spring/boot/annotation/EnableLineMessaging.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.spring.boot.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import com.linecorp.bot.spring.boot.support.LineMessageHandlerSupport; 25 | 26 | /** 27 | * Adding this annotation to an {@code @Configuration} class imports the 28 | * {@link LineMessageHandlerSupport}. 29 | * 30 | * @see LineMessageHandlerSupport 31 | */ 32 | @Target(ElementType.TYPE) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | public @interface EnableLineMessaging {} 35 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/LocationMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonTypeName; 20 | 21 | import lombok.Value; 22 | 23 | /** 24 | * Location message 25 | */ 26 | @Value 27 | @JsonTypeName("location") 28 | public class LocationMessage implements Message { 29 | /** 30 | * Title 31 | */ 32 | private final String title; 33 | 34 | /** 35 | * Address 36 | */ 37 | private final String address; 38 | 39 | /** 40 | * Latitude 41 | */ 42 | private final double latitude; 43 | 44 | /** 45 | * Longitude 46 | */ 47 | private final double longitude; 48 | } 49 | -------------------------------------------------------------------------------- /sample-spring-boot-kitchensink/src/main/java/com/example/bot/spring/KitchenSinkApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.example.bot.spring; 18 | 19 | import java.io.IOException; 20 | import java.nio.file.Files; 21 | import java.nio.file.Path; 22 | 23 | import org.springframework.boot.SpringApplication; 24 | import org.springframework.boot.autoconfigure.SpringBootApplication; 25 | 26 | @SpringBootApplication 27 | public class KitchenSinkApplication { 28 | static Path downloadedContentDir; 29 | 30 | public static void main(String[] args) throws IOException { 31 | downloadedContentDir = Files.createTempDirectory("line-bot"); 32 | SpringApplication.run(KitchenSinkApplication.class, args); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /line-bot-model/src/test/java/com/linecorp/bot/model/testutil/TestUtil.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model.testutil; 2 | 3 | import com.fasterxml.jackson.databind.DeserializationFeature; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; 6 | import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; 7 | 8 | import lombok.experimental.UtilityClass; 9 | 10 | @UtilityClass 11 | public class TestUtil { 12 | /** 13 | * ObjectMapper which same configuration for production except failOnUnknownProperties is configurable. 14 | * @param failOnUnknownProperties for testing, if true, exception thrown when unknown properties found. 15 | */ 16 | public static ObjectMapper objectMapperWithProductionConfiguration(final boolean failOnUnknownProperties) { 17 | return new ObjectMapper() 18 | .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, failOnUnknownProperties) 19 | // Register ParameterNamesModule to read parameter name from lombok generated constructor. 20 | .registerModule(new ParameterNamesModule()) 21 | // Register JSR-310(java.time.temporal.*) module and read number as millsec. 22 | .registerModule(new JavaTimeModule()) 23 | .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /line-bot-api-client/src/test/java/com/linecorp/bot/client/LineMessagingClientImplRichMenuWiremockTest.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.client; 2 | 3 | import static java.util.Collections.emptyList; 4 | import static org.assertj.core.api.Assertions.assertThat; 5 | 6 | import org.junit.Test; 7 | 8 | import com.linecorp.bot.model.response.BotApiResponse; 9 | 10 | import okhttp3.mockwebserver.MockResponse; 11 | 12 | public class LineMessagingClientImplRichMenuWiremockTest extends AbstractWiremockTest { 13 | public static final BotApiResponse SUCCESS = new BotApiResponse("", emptyList()); 14 | 15 | @Test(timeout = ASYNC_TEST_TIMEOUT) 16 | public void status200WithoutBodyTest() throws Exception { 17 | // Mocking 18 | mockWebServer.enqueue(new MockResponse().setResponseCode(200)); 19 | 20 | // Do 21 | final BotApiResponse botApiResponse = lineMessagingClient.deleteRichMenu("RICH_MENU_ID").get(); 22 | assertThat(botApiResponse).isEqualTo(SUCCESS); 23 | } 24 | 25 | @Test(timeout = ASYNC_TEST_TIMEOUT) 26 | public void status200WithBodyTest() throws Exception { 27 | // Mocking 28 | mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); 29 | 30 | // Do 31 | final BotApiResponse botApiResponse = lineMessagingClient.deleteRichMenu("RICH_MENU_ID").get(); 32 | assertThat(botApiResponse).isEqualTo(SUCCESS); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/message/VideoMessageContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.annotation.JsonTypeName; 22 | 23 | import lombok.Value; 24 | 25 | @Value 26 | @JsonTypeName("video") 27 | public class VideoMessageContent implements MessageContent { 28 | private final String id; 29 | private final String url; 30 | 31 | @JsonCreator 32 | public VideoMessageContent( 33 | @JsonProperty("id") String id, 34 | @JsonProperty("url") String url) { 35 | this.id = id; 36 | this.url = url; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /line-bot-model/src/test/java/com/linecorp/bot/model/message/imagemap/MessageImagemapActionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.imagemap; 18 | 19 | import static org.assertj.core.api.Java6Assertions.assertThat; 20 | 21 | import org.junit.Test; 22 | 23 | import com.fasterxml.jackson.databind.ObjectMapper; 24 | 25 | public class MessageImagemapActionTest { 26 | @Test 27 | public void getText() throws Exception { 28 | MessageImagemapAction imageMapAction = new MessageImagemapAction("hoge", new ImagemapArea(1, 2, 3, 4)); 29 | 30 | ObjectMapper objectMapper = new ObjectMapper(); 31 | String s = objectMapper.writeValueAsString(imageMapAction); 32 | assertThat(s).contains("\"type\":\"message\""); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/imagemap/ImagemapArea.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.imagemap; 18 | 19 | import lombok.Value; 20 | 21 | /** 22 | * Defines the size of the full imagemap with the width as 1040px. The top left is used as the origin of the area. 23 | */ 24 | @Value 25 | public class ImagemapArea { 26 | /** 27 | * Horizontal position of the tappable area 28 | */ 29 | private final int x; 30 | 31 | /** 32 | * Vertical position of the tappable area 33 | */ 34 | private final int y; 35 | 36 | /** 37 | * Width of the tappable area 38 | */ 39 | private final int width; 40 | 41 | /** 42 | * Height of the tappable area 43 | */ 44 | private final int height; 45 | } 46 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/response/BotApiResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.response; 18 | 19 | import java.util.Collections; 20 | import java.util.List; 21 | 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | 24 | import lombok.Value; 25 | 26 | /** 27 | * Generic response object for LINE Messaging API. 28 | */ 29 | @Value 30 | public class BotApiResponse { 31 | private final String message; 32 | private final List details; 33 | 34 | public BotApiResponse( 35 | @JsonProperty("message") String message, 36 | @JsonProperty("details") List details 37 | ) { 38 | this.message = message; 39 | this.details = details == null ? Collections.emptyList() : details; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/imagemap/ImagemapAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.imagemap; 18 | 19 | import com.fasterxml.jackson.annotation.JsonSubTypes; 20 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 21 | import com.fasterxml.jackson.annotation.JsonTypeInfo.As; 22 | 23 | /** 24 | *

25 | * Interface which specifies the actions and tappable regions of an imagemap. 26 | *

27 | */ 28 | @JsonTypeInfo( 29 | use = JsonTypeInfo.Id.NAME, 30 | include = As.PROPERTY, 31 | property = "type" 32 | ) 33 | @JsonSubTypes({ 34 | @JsonSubTypes.Type(MessageImagemapAction.class), 35 | @JsonSubTypes.Type(URIImagemapAction.class), 36 | }) 37 | public interface ImagemapAction { 38 | ImagemapArea getArea(); 39 | } 40 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/template/Template.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.template; 18 | 19 | import com.fasterxml.jackson.annotation.JsonSubTypes; 20 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 21 | import com.fasterxml.jackson.annotation.JsonTypeInfo.As; 22 | 23 | /** 24 | * Interface for Template message 25 | */ 26 | @JsonSubTypes({ 27 | @JsonSubTypes.Type(ButtonsTemplate.class), 28 | @JsonSubTypes.Type(CarouselTemplate.class), 29 | @JsonSubTypes.Type(ConfirmTemplate.class), 30 | @JsonSubTypes.Type(ImageCarouselTemplate.class), 31 | }) 32 | @JsonTypeInfo( 33 | use = JsonTypeInfo.Id.NAME, 34 | include = As.PROPERTY, 35 | property = "type" 36 | ) 37 | public interface Template { 38 | } 39 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/action/Action.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.action; 18 | 19 | import com.fasterxml.jackson.annotation.JsonSubTypes; 20 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 21 | import com.fasterxml.jackson.annotation.JsonTypeInfo.As; 22 | 23 | /** 24 | * Abstract interface for Template message actions. 25 | */ 26 | @JsonTypeInfo( 27 | use = JsonTypeInfo.Id.NAME, 28 | include = As.PROPERTY, 29 | property = "type" 30 | ) 31 | @JsonSubTypes({ 32 | @JsonSubTypes.Type(PostbackAction.class), 33 | @JsonSubTypes.Type(URIAction.class), 34 | @JsonSubTypes.Type(MessageAction.class), 35 | @JsonSubTypes.Type(DatetimePickerAction.class), 36 | }) 37 | public interface Action { 38 | String getLabel(); 39 | } 40 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/source/RoomSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.source; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.annotation.JsonTypeName; 22 | 23 | import lombok.Value; 24 | 25 | @Value 26 | @JsonTypeName("room") 27 | public class RoomSource implements Source { 28 | private final String userId; 29 | private final String roomId; 30 | 31 | @JsonCreator 32 | public RoomSource(@JsonProperty("userId") String userId, @JsonProperty("roomId") String roomId) { 33 | this.userId = userId; 34 | this.roomId = roomId; 35 | } 36 | 37 | @Override 38 | public String getSenderId() { 39 | return roomId; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/TemplateMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonTypeName; 20 | 21 | import com.linecorp.bot.model.message.template.Template; 22 | 23 | import lombok.Value; 24 | 25 | /** 26 | * Template messages are messages with predefined layouts which you can customize. There are three types of 27 | * templates available that can be used to interact with users through your bot. 28 | */ 29 | @Value 30 | @JsonTypeName("template") 31 | public class TemplateMessage implements Message { 32 | /** 33 | * Alternative text 34 | */ 35 | private final String altText; 36 | 37 | /** 38 | * Object with the contents of the template. 39 | */ 40 | private final Template template; 41 | } 42 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/postback/PostbackContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.postback; 18 | 19 | import java.util.Map; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | 24 | import lombok.Value; 25 | 26 | /** 27 | * Content of the postback event. 28 | */ 29 | @Value 30 | public class PostbackContent { 31 | /** 32 | * Postback data 33 | */ 34 | private final String data; 35 | private final Map params; 36 | 37 | @JsonCreator 38 | public PostbackContent( 39 | @JsonProperty("data") String data, 40 | @JsonProperty("params") Map params) { 41 | this.data = data; 42 | this.params = params; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/imagemap/MessageImagemapAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.imagemap; 18 | 19 | import com.fasterxml.jackson.annotation.JsonProperty; 20 | import com.fasterxml.jackson.annotation.JsonTypeName; 21 | 22 | import lombok.Value; 23 | 24 | @Value 25 | @JsonTypeName("message") 26 | public class MessageImagemapAction implements ImagemapAction { 27 | /** 28 | * Message to send 29 | */ 30 | private final String text; 31 | /** 32 | * Defined tappable area 33 | */ 34 | private final ImagemapArea area; 35 | 36 | public MessageImagemapAction(@JsonProperty("text") String text, 37 | @JsonProperty("area") ImagemapArea area) { 38 | this.text = text; 39 | this.area = area; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/PushMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model; 18 | 19 | import java.util.Collections; 20 | import java.util.List; 21 | 22 | import com.linecorp.bot.model.message.Message; 23 | 24 | import lombok.AllArgsConstructor; 25 | import lombok.Value; 26 | 27 | /** 28 | * Send messages to users, groups, and rooms at any time. 29 | */ 30 | @Value 31 | @AllArgsConstructor 32 | public class PushMessage { 33 | /** 34 | * ID of the receiver 35 | */ 36 | private final String to; 37 | 38 | /** 39 | * List of Message objects.
40 | * Max: 5 41 | */ 42 | private final List messages; 43 | 44 | public PushMessage(String to, Message message) { 45 | this.to = to; 46 | this.messages = Collections.singletonList(message); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/VideoMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonTypeName; 20 | 21 | import lombok.Value; 22 | 23 | @Value 24 | @JsonTypeName("video") 25 | public class VideoMessage implements Message { 26 | /** 27 | * URL of video file 28 | *
    29 | *
  • HTTPS
  • 30 | *
  • mp4
  • 31 | *
  • Less than 1 minute
  • 32 | *
  • Max: 10 MB
  • 33 | *
34 | */ 35 | private final String originalContentUrl; 36 | 37 | /** 38 | * URL of preview image 39 | *
    40 | *
  • HTTPS
  • 41 | *
  • JPEG
  • 42 | *
  • Max: 240 x 240
  • 43 | *
  • Max: 1 MB
  • 44 | *
45 | */ 46 | private final String previewImageUrl; 47 | } 48 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/message/TextMessageContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.annotation.JsonTypeName; 22 | 23 | import lombok.Value; 24 | 25 | /** 26 | * Message content for text 27 | */ 28 | @Value 29 | @JsonTypeName("text") 30 | public class TextMessageContent implements MessageContent { 31 | private final String id; 32 | /** 33 | * Message text 34 | */ 35 | private final String text; 36 | 37 | @JsonCreator 38 | public TextMessageContent( 39 | @JsonProperty("id") String id, 40 | @JsonProperty("text") String text) { 41 | this.id = id; 42 | this.text = text; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/imagemap/URIImagemapAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.imagemap; 18 | 19 | import com.fasterxml.jackson.annotation.JsonProperty; 20 | import com.fasterxml.jackson.annotation.JsonTypeName; 21 | 22 | import lombok.Value; 23 | 24 | /** 25 | * 26 | */ 27 | @Value 28 | @JsonTypeName("uri") 29 | public class URIImagemapAction implements ImagemapAction { 30 | /** 31 | * Webpage URL 32 | */ 33 | private final String linkUri; 34 | 35 | /** 36 | * Defined tappable area 37 | */ 38 | private final ImagemapArea area; 39 | 40 | public URIImagemapAction(@JsonProperty("linkUri") String linkUri, 41 | @JsonProperty("area") ImagemapArea area) { 42 | this.linkUri = linkUri; 43 | this.area = area; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /line-bot-spring-boot/src/main/java/com/linecorp/bot/spring/boot/annotation/LineMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.spring.boot.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import org.springframework.stereotype.Component; 25 | 26 | import com.google.common.annotations.Beta; 27 | 28 | /** 29 | * Indicates that an annotated class has a LINE Messaging Event Handler method. 30 | * 31 | *

This annotation serves as a specialization of {@link Component @Component}, 32 | * allowing for implementation classes to be autodetected through classpath scanning. 33 | */ 34 | @Beta 35 | @Target(ElementType.TYPE) 36 | @Component 37 | @Retention(RetentionPolicy.RUNTIME) 38 | public @interface LineMessageHandler {} 39 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/source/Source.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.source; 18 | 19 | import com.fasterxml.jackson.annotation.JsonSubTypes; 20 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 21 | 22 | @JsonSubTypes({ 23 | @JsonSubTypes.Type(UserSource.class), 24 | @JsonSubTypes.Type(GroupSource.class), 25 | @JsonSubTypes.Type(RoomSource.class), 26 | }) 27 | @JsonTypeInfo( 28 | use = JsonTypeInfo.Id.NAME, 29 | include = JsonTypeInfo.As.PROPERTY, 30 | property = "type", 31 | defaultImpl = UnknownSource.class, 32 | visible = true 33 | ) 34 | public interface Source { 35 | String getUserId(); 36 | 37 | /** 38 | * message/event sender id. It might be userId/roomId/roomId. 39 | * @return message/event sender id 40 | */ 41 | String getSenderId(); 42 | } 43 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/template/ImageCarouselTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.template; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.annotation.JsonTypeName; 22 | import lombok.Value; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Template message with multiple columns which can be cycled like a carousel. 28 | */ 29 | @Value 30 | @JsonTypeName("image_carousel") 31 | public class ImageCarouselTemplate implements Template { 32 | /** 33 | * List of columns(Max: 5) 34 | */ 35 | private final List columns; 36 | 37 | @JsonCreator 38 | public ImageCarouselTemplate(@JsonProperty("columns") List columns) { 39 | this.columns = columns; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/message/FileMessageContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.annotation.JsonTypeName; 22 | 23 | import lombok.Value; 24 | 25 | @Value 26 | @JsonTypeName("file") 27 | public class FileMessageContent implements MessageContent { 28 | private final String id; 29 | private final String fileName; 30 | private final int fileSize; 31 | 32 | @JsonCreator 33 | public FileMessageContent( 34 | @JsonProperty("id") String id, 35 | @JsonProperty("fileName") String fileName, 36 | @JsonProperty("fileSize") int fileSize) { 37 | this.id = id; 38 | this.fileName = fileName; 39 | this.fileSize = fileSize; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /line-bot-api-client/src/test/java/com/linecorp/bot/client/FixedChannelTokenSupplierTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import static org.assertj.core.api.Assertions.fail; 21 | 22 | import org.junit.Test; 23 | 24 | public class FixedChannelTokenSupplierTest { 25 | @Test(expected = NullPointerException.class) 26 | public void constructedInstanceAlwaysNonNullTest() { 27 | // Do 28 | FixedChannelTokenSupplier.of(null); 29 | 30 | // Verify 31 | fail("NullPointerException is not occurred."); 32 | } 33 | 34 | @Test 35 | public void getTest() { 36 | ChannelTokenSupplier target = FixedChannelTokenSupplier.of("FIXED_TOKEN"); 37 | 38 | // DO 39 | String result = target.get(); 40 | 41 | // Verify 42 | assertThat(result).isEqualTo("FIXED_TOKEN"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/source/GroupSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.source; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.annotation.JsonTypeName; 22 | 23 | import lombok.Value; 24 | 25 | @Value 26 | @JsonTypeName("group") 27 | public class GroupSource implements Source { 28 | private final String groupId; 29 | private final String userId; 30 | 31 | /** 32 | * Create new instance. 33 | * @param groupId group ID 34 | * @param userId user id may be null 35 | */ 36 | @JsonCreator 37 | public GroupSource( 38 | @JsonProperty("groupId") String groupId, 39 | @JsonProperty("userId") String userId 40 | ) { 41 | this.groupId = groupId; 42 | this.userId = userId; 43 | } 44 | 45 | @Override 46 | public String getSenderId() { 47 | return groupId; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/template/ConfirmTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.template; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import com.fasterxml.jackson.annotation.JsonCreator; 23 | import com.fasterxml.jackson.annotation.JsonProperty; 24 | import com.fasterxml.jackson.annotation.JsonTypeName; 25 | 26 | import com.linecorp.bot.model.action.Action; 27 | 28 | import lombok.Value; 29 | 30 | @Value 31 | @JsonTypeName("confirm") 32 | public class ConfirmTemplate implements Template { 33 | private final String text; 34 | private final List actions; 35 | 36 | @JsonCreator 37 | public ConfirmTemplate(@JsonProperty("text") String text, @JsonProperty("actions") List actions) { 38 | this.text = text; 39 | this.actions = actions; 40 | } 41 | 42 | public ConfirmTemplate(String text, Action left, Action right) { 43 | this(text, Arrays.asList(left, right)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/exception/LineMessagingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client.exception; 18 | 19 | import com.linecorp.bot.model.error.ErrorResponse; 20 | 21 | import lombok.Getter; 22 | 23 | @Getter 24 | public abstract class LineMessagingException extends Exception { 25 | static final long SERIAL_VERSION_UID = 0x001_003; // 1.3.x 26 | private static final long serialVersionUID = SERIAL_VERSION_UID; 27 | 28 | /** 29 | * Original error response from server. 30 | * 31 | * Null when error response is not exist. 32 | */ 33 | private final ErrorResponse errorResponse; 34 | 35 | LineMessagingException(final String message, final ErrorResponse errorResponse, 36 | final Throwable cause) { 37 | super(message, cause); 38 | this.errorResponse = errorResponse; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return super.toString() + ", " + errorResponse; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/message/StickerMessageContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.annotation.JsonTypeName; 22 | 23 | import lombok.Value; 24 | 25 | /** 26 | * Message content for sticker type. 27 | */ 28 | @Value 29 | @JsonTypeName("sticker") 30 | public class StickerMessageContent implements MessageContent { 31 | private final String id; 32 | 33 | /** 34 | * 35 | */ 36 | private final String packageId; 37 | private final String stickerId; 38 | 39 | @JsonCreator 40 | public StickerMessageContent( 41 | @JsonProperty("id") String id, 42 | @JsonProperty("packageId") String packageId, 43 | @JsonProperty("stickerId") String stickerId) { 44 | this.id = id; 45 | this.packageId = packageId; 46 | this.stickerId = stickerId; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/LeaveEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event; 18 | 19 | import java.time.Instant; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.annotation.JsonTypeName; 24 | 25 | import com.linecorp.bot.model.event.source.Source; 26 | 27 | import lombok.Value; 28 | 29 | /** 30 | * Event object for when your account leaves a group. 31 | */ 32 | @Value 33 | @JsonTypeName("leave") 34 | public class LeaveEvent implements Event { 35 | /** 36 | * JSON object which contains the source of the event 37 | */ 38 | private final Source source; 39 | 40 | /** 41 | * Time of the event 42 | */ 43 | private final Instant timestamp; 44 | 45 | @JsonCreator 46 | public LeaveEvent( 47 | @JsonProperty("source") Source source, 48 | @JsonProperty("timestamp") Instant timestamp) { 49 | this.source = source; 50 | this.timestamp = timestamp; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/UnfollowEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event; 18 | 19 | import java.time.Instant; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.annotation.JsonTypeName; 24 | 25 | import com.linecorp.bot.model.event.source.Source; 26 | 27 | import lombok.Value; 28 | 29 | /** 30 | * Event object for when your account is blocked. 31 | */ 32 | @Value 33 | @JsonTypeName("unfollow") 34 | public class UnfollowEvent implements Event { 35 | /** 36 | * JSON object which contains the source of the event 37 | */ 38 | private final Source source; 39 | 40 | /** 41 | * Time of the event 42 | */ 43 | private final Instant timestamp; 44 | 45 | @JsonCreator 46 | public UnfollowEvent( 47 | @JsonProperty("source") Source source, 48 | @JsonProperty("timestamp") Instant timestamp) { 49 | this.source = source; 50 | this.timestamp = timestamp; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sample-spring-boot-kitchensink/src/main/java/com/example/bot/spring/KitchenSinkWebMvcConfigurer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.example.bot.spring; 18 | 19 | import org.springframework.context.annotation.Configuration; 20 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 21 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 22 | 23 | import lombok.extern.slf4j.Slf4j; 24 | 25 | @Configuration 26 | @Slf4j 27 | public class KitchenSinkWebMvcConfigurer extends WebMvcConfigurerAdapter { 28 | @Override 29 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 30 | 31 | String downloadedContentUri = KitchenSinkApplication.downloadedContentDir 32 | .toUri().toASCIIString(); 33 | log.info("downloaded dir: {}", downloadedContentUri); 34 | registry.addResourceHandler("/downloaded/**") 35 | .addResourceLocations(downloadedContentUri); 36 | registry.addResourceHandler("/static/**") 37 | .addResourceLocations("classpath:/static/"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/MessageContentResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | import lombok.Builder; 25 | import lombok.Getter; 26 | import lombok.ToString; 27 | 28 | @Getter 29 | @Builder 30 | @ToString 31 | public class MessageContentResponse implements AutoCloseable { 32 | /** File size of this content. */ 33 | final long length; 34 | 35 | /** File input stream of this content. */ 36 | final InputStream stream; 37 | 38 | /** File contents type represented by MIME. */ 39 | final String mimeType; 40 | 41 | /** All HTTP headers of API response. 42 | * 43 | * Note: there are no SPEC for those headers. 44 | * Current field values are provided AS-IS and can be changed/removed without announces. 45 | */ 46 | final Map> allHeaders; 47 | 48 | @Override 49 | public void close() throws IOException { 50 | stream.close(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/UnknownEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event; 18 | 19 | import java.time.Instant; 20 | 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | import com.linecorp.bot.model.event.source.Source; 24 | 25 | import lombok.Value; 26 | 27 | /** 28 | * Fallback event type for {@link Event}. 29 | */ 30 | @Value 31 | public class UnknownEvent implements Event { 32 | /** 33 | * Type of the event. 34 | */ 35 | private final String type; 36 | 37 | /** 38 | * JSON object which contains the source of the event 39 | */ 40 | private final Source source; 41 | 42 | /** 43 | * Time of the event 44 | */ 45 | private final Instant timestamp; 46 | 47 | public UnknownEvent( 48 | @JsonProperty("type") String type, 49 | @JsonProperty("source") Source source, 50 | @JsonProperty("timestamp") Instant timestamp 51 | ) { 52 | this.type = type; 53 | this.source = source; 54 | this.timestamp = timestamp; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /line-bot-model/src/test/java/com/linecorp/bot/model/message/imagemap/URIImagemapActionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.imagemap; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | 21 | import org.junit.Test; 22 | 23 | import com.fasterxml.jackson.databind.DeserializationFeature; 24 | import com.fasterxml.jackson.databind.ObjectMapper; 25 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; 26 | 27 | public class URIImagemapActionTest { 28 | @Test 29 | public void getLinkUri() throws Exception { 30 | URIImagemapAction imageMapAction = new URIImagemapAction("http://example.com", 31 | new ImagemapArea(1, 2, 3, 4)); 32 | 33 | ObjectMapper objectMapper = new ObjectMapper() 34 | .registerModule(new JavaTimeModule()) 35 | .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); 36 | String s = objectMapper.writeValueAsString(imageMapAction); 37 | assertThat(s).contains("\"type\":\"uri\""); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/HeaderInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client; 18 | 19 | import java.io.IOException; 20 | 21 | import lombok.AllArgsConstructor; 22 | import okhttp3.Interceptor; 23 | import okhttp3.Request; 24 | import okhttp3.Response; 25 | 26 | @AllArgsConstructor(staticName = "forChannelTokenSupplier") 27 | class HeaderInterceptor implements Interceptor { 28 | private static final String USER_AGENT = 29 | "line-botsdk-java/" + HeaderInterceptor.class.getPackage().getImplementationVersion(); 30 | private final ChannelTokenSupplier channelTokenSupplier; 31 | 32 | @Override 33 | public Response intercept(Chain chain) throws IOException { 34 | final String channelToken = channelTokenSupplier.get(); 35 | Request request = chain.request().newBuilder() 36 | .addHeader("Authorization", "Bearer " + channelToken) 37 | .addHeader("User-Agent", USER_AGENT) 38 | .build(); 39 | return chain.proceed(request); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/message/MessageContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonSubTypes; 20 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 21 | 22 | /** 23 | * Abstract inteface of the message content 24 | */ 25 | @JsonSubTypes({ 26 | @JsonSubTypes.Type(TextMessageContent.class), 27 | @JsonSubTypes.Type(ImageMessageContent.class), 28 | @JsonSubTypes.Type(LocationMessageContent.class), 29 | @JsonSubTypes.Type(AudioMessageContent.class), 30 | @JsonSubTypes.Type(VideoMessageContent.class), 31 | @JsonSubTypes.Type(StickerMessageContent.class), 32 | @JsonSubTypes.Type(FileMessageContent.class), 33 | }) 34 | @JsonTypeInfo( 35 | use = JsonTypeInfo.Id.NAME, 36 | include = JsonTypeInfo.As.PROPERTY, 37 | property = "type", 38 | defaultImpl = UnknownMessageContent.class, 39 | visible = true 40 | ) 41 | public interface MessageContent { 42 | /** 43 | * Get the message ID 44 | */ 45 | String getId(); 46 | } 47 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/action/URIAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.action; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | import com.fasterxml.jackson.annotation.JsonTypeName; 23 | 24 | import lombok.Value; 25 | 26 | /** 27 | * When this action is tapped, the URI specified in the uri field is opened. 28 | */ 29 | @Value 30 | @JsonIgnoreProperties(ignoreUnknown = true) 31 | @JsonTypeName("uri") 32 | public class URIAction implements Action { 33 | /** 34 | * Label for the action
35 | * Max: 20 characters 36 | */ 37 | private final String label; 38 | 39 | /** 40 | * URI opened when the action is performed
41 | * http, https, tel 42 | */ 43 | private final String uri; 44 | 45 | @JsonCreator 46 | public URIAction( 47 | @JsonProperty("label") String label, 48 | @JsonProperty("uri") String uri) { 49 | this.label = label; 50 | this.uri = uri; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/richmenu/RichMenuResponse.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model.richmenu; 2 | 3 | import java.util.List; 4 | 5 | import com.fasterxml.jackson.annotation.JsonCreator; 6 | 7 | import lombok.Value; 8 | 9 | @Value 10 | public class RichMenuResponse implements RichMenuCommonProperties { 11 | /** Rich menu ID */ 12 | String richMenuId; 13 | 14 | /** 15 | * {@link RichMenuSize} object which contains the width and height of the rich menu displayed in the chat. 16 | * 17 | *

Rich menu images must be one of the following sizes: 2500x1686, 2500x843. 18 | */ 19 | RichMenuSize size; 20 | 21 | /** true to display the rich menu by default. Otherwise, false. */ 22 | boolean selected; 23 | 24 | /** 25 | * Name of the rich menu. This value can be used to help manage your rich menus and is not displayed to users. 26 | * 27 | *

Maximum of 300 characters. 28 | */ 29 | String name; 30 | 31 | /** 32 | * Text displayed in the chat bar. 33 | * 34 | *

Maximum of 14 characters. 35 | */ 36 | String chatBarText; 37 | 38 | /** 39 | * Array of {@link RichMenuArea} objects which define the coordinates and size of tappable areas. 40 | * 41 | *

Maximum of 20 area objects. 42 | */ 43 | List areas; 44 | 45 | @JsonCreator 46 | public RichMenuResponse(final String richMenuId, final RichMenuSize size, final boolean selected, 47 | final String name, final String chatBarText, final List areas) { 48 | this.richMenuId = richMenuId; 49 | this.size = size; 50 | this.selected = selected; 51 | this.name = name; 52 | this.chatBarText = chatBarText; 53 | this.areas = areas; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/action/MessageAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.action; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | import com.fasterxml.jackson.annotation.JsonTypeName; 23 | 24 | import lombok.Value; 25 | 26 | /** 27 | * When this action is tapped, the string in the text field is sent as a message from the user. 28 | */ 29 | @Value 30 | @JsonIgnoreProperties(ignoreUnknown = true) 31 | @JsonTypeName("message") 32 | public class MessageAction implements Action { 33 | /** 34 | *Label for the action. Max 20 characters. 35 | */ 36 | private final String label; 37 | 38 | /** 39 | * Text sent when the action is performed 40 | * Max: 300 characters 41 | */ 42 | private final String text; 43 | 44 | @JsonCreator 45 | public MessageAction( 46 | @JsonProperty("label") String label, 47 | @JsonProperty("text") String text) { 48 | this.label = label; 49 | this.text = text; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/ImagemapMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message; 18 | 19 | import java.util.List; 20 | 21 | import com.fasterxml.jackson.annotation.JsonTypeName; 22 | 23 | import com.linecorp.bot.model.message.imagemap.ImagemapAction; 24 | import com.linecorp.bot.model.message.imagemap.ImagemapBaseSize; 25 | 26 | import lombok.Value; 27 | 28 | /** 29 | * Imagemaps are images with one or more links. You can assign one link for the entire image or multiple 30 | * links which correspond to different regions of the image. 31 | */ 32 | @Value 33 | @JsonTypeName("imagemap") 34 | public class ImagemapMessage implements Message { 35 | /** 36 | * Base URL 37 | * 38 | *

    39 | *
  • HTTPS required
  • 40 | *
41 | */ 42 | private final String baseUrl; 43 | 44 | /** 45 | * Alternative text 46 | */ 47 | private final String altText; 48 | 49 | /** 50 | * Size of base image 51 | */ 52 | private final ImagemapBaseSize baseSize; 53 | 54 | /** 55 | * Action when tapped 56 | */ 57 | private final List actions; 58 | } 59 | -------------------------------------------------------------------------------- /line-bot-model/src/test/java/com/linecorp/bot/model/event/beacon/BeaconContentTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.beacon; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | 21 | import org.junit.Test; 22 | 23 | public class BeaconContentTest { 24 | @Test 25 | public void beaconContentEqualityTest() { 26 | BeaconContent upperCase = new BeaconContent("hwid", "enter", "01ab"); 27 | BeaconContent lowerCase = new BeaconContent("hwid", "enter", "01AB"); 28 | 29 | // Verify 30 | assertThat(upperCase).isEqualTo(lowerCase); 31 | } 32 | 33 | @Test 34 | public void beaconContentArrayProtectedTest() { 35 | BeaconContent target = new BeaconContent("hwid", "enter", "01"); 36 | 37 | // Precondition 38 | assertThat(target.getDeviceMessage()) 39 | .hasSize(1) 40 | .containsExactly(0x01); 41 | 42 | // Do 43 | target.getDeviceMessage()[0] = (byte) 0xcd; 44 | 45 | // Verify 46 | assertThat(target.getDeviceMessage()[0]) 47 | .isEqualTo((byte) 0x01) 48 | .isNotEqualTo((byte) 0xcd); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/profile/UserProfileResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.profile; 18 | 19 | import com.fasterxml.jackson.annotation.JsonProperty; 20 | 21 | import lombok.Value; 22 | 23 | /** 24 | * Response object for 'Get Profile' API. 25 | */ 26 | @Value 27 | public class UserProfileResponse { 28 | /** 29 | * Display name 30 | */ 31 | private final String displayName; 32 | 33 | /** 34 | * User ID 35 | */ 36 | private final String userId; 37 | 38 | /** 39 | * Image URL 40 | */ 41 | private final String pictureUrl; 42 | 43 | /** 44 | * Status message 45 | */ 46 | private final String statusMessage; 47 | 48 | public UserProfileResponse( 49 | @JsonProperty("displayName") String displayName, 50 | @JsonProperty("userId") String userId, 51 | @JsonProperty("pictureUrl") String pictureUrl, 52 | @JsonProperty("statusMessage") String statusMessage) { 53 | this.displayName = displayName; 54 | this.userId = userId; 55 | this.pictureUrl = pictureUrl; 56 | this.statusMessage = statusMessage; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event; 18 | 19 | import java.time.Instant; 20 | 21 | import com.fasterxml.jackson.annotation.JsonSubTypes; 22 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 23 | 24 | import com.linecorp.bot.model.event.source.Source; 25 | 26 | /** 27 | * Abstract interface of events. 28 | */ 29 | @JsonSubTypes({ 30 | @JsonSubTypes.Type(MessageEvent.class), 31 | @JsonSubTypes.Type(UnfollowEvent.class), 32 | @JsonSubTypes.Type(FollowEvent.class), 33 | @JsonSubTypes.Type(JoinEvent.class), 34 | @JsonSubTypes.Type(LeaveEvent.class), 35 | @JsonSubTypes.Type(PostbackEvent.class), 36 | @JsonSubTypes.Type(BeaconEvent.class) 37 | }) 38 | @JsonTypeInfo( 39 | use = JsonTypeInfo.Id.NAME, 40 | include = JsonTypeInfo.As.PROPERTY, 41 | property = "type", 42 | defaultImpl = UnknownEvent.class, 43 | visible = true 44 | ) 45 | public interface Event { 46 | /** 47 | * Get event source 48 | */ 49 | Source getSource(); 50 | 51 | /** 52 | * Time of the event 53 | */ 54 | Instant getTimestamp(); 55 | } 56 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/template/ImageCarouselColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.template; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.linecorp.bot.model.action.Action; 22 | import lombok.Value; 23 | 24 | import java.util.Collections; 25 | import java.util.List; 26 | 27 | /** 28 | * Column object for carousel template 29 | */ 30 | @Value 31 | public class ImageCarouselColumn { 32 | /** 33 | * Image URL 34 | *
    35 | *
  • Max 1000 characters HTTPS URL
  • 36 | *
  • JPEG or PNG
  • 37 | *
  • Aspect ratio: 1:1
  • 38 | *
  • Max width: 1024px
  • 39 | *
  • Max: 1 MB
  • 40 | *
41 | */ 42 | private final String imageUrl; 43 | 44 | /** 45 | * Action when tapped 46 | */ 47 | private final Action action; 48 | 49 | @JsonCreator 50 | public ImageCarouselColumn( 51 | @JsonProperty("imageUrl") String imageUrl, 52 | @JsonProperty("action") Action action) { 53 | this.imageUrl = imageUrl; 54 | this.action = action; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /line-bot-model/src/test/java/com/linecorp/bot/model/event/MessageEventTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | 21 | import java.lang.reflect.Constructor; 22 | import java.lang.reflect.Method; 23 | 24 | import org.junit.Test; 25 | 26 | import com.linecorp.bot.model.event.message.MessageContent; 27 | 28 | public class MessageEventTest { 29 | @Test 30 | public void constructor2ndParameterBinaryCompatibilityTest() { 31 | Constructor constructor = MessageEvent.class.getConstructors()[0]; 32 | 33 | Class[] parameterTypes = constructor.getParameterTypes(); 34 | assertThat(parameterTypes).hasSize(4); 35 | assertThat(parameterTypes[2]).isEqualTo(MessageContent.class) 36 | .isNotEqualTo(Object.class); 37 | } 38 | 39 | @Test 40 | public void getMessageBinaryCompatibilityTest() throws NoSuchMethodException { 41 | Method method = MessageEvent.class.getMethod("getMessage"); 42 | 43 | assertThat(method.getReturnType()).isEqualTo(MessageContent.class) 44 | .isNotEqualTo(Object.class); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/ReplyMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model; 18 | 19 | import java.util.Collections; 20 | import java.util.List; 21 | 22 | import com.linecorp.bot.model.message.Message; 23 | 24 | import lombok.AllArgsConstructor; 25 | import lombok.Value; 26 | 27 | /** 28 | *

29 | * Respond to events from users, groups, and rooms. 30 | *

31 | *

32 | * Webhooks are used to notify you when an event occurs. For events that you can respond to, a replyToken is issued for replying to messages. 33 | *

34 | *

35 | * Because the replyToken becomes invalid after a certain period of time, responses should be sent as soon as a message is received. Reply tokens can only be used once. 36 | *

37 | */ 38 | @Value 39 | @AllArgsConstructor 40 | public class ReplyMessage { 41 | /** 42 | * replyToken received via webhook 43 | */ 44 | private final String replyToken; 45 | 46 | /** 47 | * List of messages.
48 | * Max: 5 49 | */ 50 | private final List messages; 51 | 52 | public ReplyMessage(String replyToken, Message message) { 53 | this(replyToken, Collections.singletonList(message)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /line-bot-spring-boot/src/main/java/com/linecorp/bot/spring/boot/annotation/EventMapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.spring.boot.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import com.google.common.annotations.Beta; 25 | 26 | /** 27 | * Indicates that an annotated method is a LINE Messaging Event Handler. 28 | * 29 | * Note: Only {@link EventMapping @EventMapping} annotated method 30 | * in the class annotated by {@link LineMessageHandler @LineMessageHandler} is enabled. 31 | */ 32 | @Beta 33 | @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) 34 | @Retention(RetentionPolicy.RUNTIME) 35 | public @interface EventMapping { 36 | int DEFAULT_PRIORITY_VALUE = -1; 37 | int DEFAULT_PRIORITY_FOR_EVENT_IFACE = 0; 38 | int DEFAULT_PRIORITY_FOR_IFACE = 100; 39 | int DEFAULT_PRIORITY_FOR_CLASS = 200; 40 | int DEFAULT_PRIORITY_FOR_PARAMETRIZED_TYPE = 300; 41 | 42 | /** 43 | * Priority of this mapping. Bigger mapping is preferentially searched and matched. 44 | */ 45 | int priority() default DEFAULT_PRIORITY_VALUE; 46 | } 47 | -------------------------------------------------------------------------------- /sample-spring-boot-echo/src/main/java/com/example/bot/spring/echo/EchoApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.example.bot.spring.echo; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | 22 | import com.linecorp.bot.model.event.Event; 23 | import com.linecorp.bot.model.event.MessageEvent; 24 | import com.linecorp.bot.model.event.message.TextMessageContent; 25 | import com.linecorp.bot.model.message.TextMessage; 26 | import com.linecorp.bot.spring.boot.annotation.EventMapping; 27 | import com.linecorp.bot.spring.boot.annotation.LineMessageHandler; 28 | 29 | @SpringBootApplication 30 | @LineMessageHandler 31 | public class EchoApplication { 32 | public static void main(String[] args) { 33 | SpringApplication.run(EchoApplication.class, args); 34 | } 35 | 36 | @EventMapping 37 | public TextMessage handleTextMessageEvent(MessageEvent event) { 38 | System.out.println("event: " + event); 39 | return new TextMessage(event.getMessage().getText()); 40 | } 41 | 42 | @EventMapping 43 | public void handleDefaultMessageEvent(Event event) { 44 | System.out.println("event: " + event); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonSubTypes; 20 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 21 | import com.fasterxml.jackson.annotation.JsonTypeInfo.As; 22 | 23 | /** 24 | * Interface of Message object. 25 | * 26 | *

JSON Deserialization

27 | * 28 | *

If you want serialize/deserialize of this object, please use Jackson's ObjectMapper with 29 | * 30 | *

.registerModule(new ParameterNamesModule());
31 | */ 32 | @JsonTypeInfo( 33 | use = JsonTypeInfo.Id.NAME, 34 | include = As.PROPERTY, 35 | property = "type" 36 | ) 37 | @JsonSubTypes({ 38 | @JsonSubTypes.Type(TextMessage.class), 39 | @JsonSubTypes.Type(ImageMessage.class), 40 | @JsonSubTypes.Type(StickerMessage.class), 41 | @JsonSubTypes.Type(LocationMessage.class), 42 | @JsonSubTypes.Type(AudioMessage.class), 43 | @JsonSubTypes.Type(VideoMessage.class), 44 | @JsonSubTypes.Type(ImagemapMessage.class), 45 | @JsonSubTypes.Type(TemplateMessage.class), 46 | }) 47 | public interface Message { 48 | } 49 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/error/ErrorResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.error; 18 | 19 | import java.util.Collections; 20 | import java.util.List; 21 | 22 | import com.fasterxml.jackson.annotation.JacksonInject; 23 | import com.fasterxml.jackson.annotation.JsonProperty; 24 | 25 | import lombok.Value; 26 | 27 | /** 28 | * Error response from LINE Messaging Server. 29 | * 30 | * @see //devdocs.line.me/#error-response 31 | */ 32 | @Value 33 | public class ErrorResponse { 34 | /** Request ID in response header */ 35 | String requestId; 36 | 37 | /** Summary or details of the error. */ 38 | String message; 39 | 40 | /** 41 | * Details of the error. 42 | * 43 | * In this class, always non-null but can be empty. 44 | */ 45 | List details; 46 | 47 | public ErrorResponse( 48 | @JacksonInject("requestId") final String requestId, 49 | @JsonProperty("message") final String message, 50 | @JsonProperty("details") final List details) { 51 | this.requestId = requestId; 52 | this.message = message; 53 | this.details = details != null ? details : Collections.emptyList(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/JoinEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event; 18 | 19 | import java.time.Instant; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.annotation.JsonTypeName; 24 | 25 | import com.linecorp.bot.model.event.source.Source; 26 | 27 | import lombok.Value; 28 | 29 | /** 30 | * Event object for when your account joins a group or talk room. You can reply to join events. 31 | */ 32 | @Value 33 | @JsonTypeName("join") 34 | public class JoinEvent implements Event, ReplyEvent { 35 | /** 36 | * Token for replying to this event 37 | */ 38 | private final String replyToken; 39 | 40 | /** 41 | * JSON object which contains the source of the event 42 | */ 43 | private final Source source; 44 | 45 | /** 46 | * Time of the event 47 | */ 48 | private final Instant timestamp; 49 | 50 | @JsonCreator 51 | public JoinEvent( 52 | @JsonProperty("replyToken") String replyToken, 53 | @JsonProperty("source") Source source, 54 | @JsonProperty("timestamp") Instant timestamp) { 55 | this.replyToken = replyToken; 56 | this.source = source; 57 | this.timestamp = timestamp; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/FollowEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event; 18 | 19 | import java.time.Instant; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.annotation.JsonTypeName; 24 | 25 | import com.linecorp.bot.model.event.source.Source; 26 | 27 | import lombok.Value; 28 | 29 | /** 30 | * Event object for when your account is added as a friend (or unblocked). You can reply to follow events. 31 | */ 32 | @Value 33 | @JsonTypeName("follow") 34 | public class FollowEvent implements Event, ReplyEvent { 35 | /** 36 | * Token for replying to this event 37 | */ 38 | private final String replyToken; 39 | 40 | /** 41 | * JSON object which contains the source of the event 42 | */ 43 | private final Source source; 44 | 45 | /** 46 | * Time of the event 47 | */ 48 | private final Instant timestamp; 49 | 50 | @JsonCreator 51 | public FollowEvent( 52 | @JsonProperty("replyToken") String replyToken, 53 | @JsonProperty("source") Source source, 54 | @JsonProperty("timestamp") Instant timestamp) { 55 | this.replyToken = replyToken; 56 | this.source = source; 57 | this.timestamp = timestamp; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /line-bot-spring-boot/src/main/java/com/linecorp/bot/spring/boot/LineBotWebMvcConfigurer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.spring.boot; 18 | 19 | import java.util.List; 20 | 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.context.annotation.Configuration; 23 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 24 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 25 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 26 | 27 | import com.linecorp.bot.spring.boot.interceptor.LineBotServerInterceptor; 28 | import com.linecorp.bot.spring.boot.support.LineBotServerArgumentProcessor; 29 | 30 | @Configuration 31 | public class LineBotWebMvcConfigurer extends WebMvcConfigurerAdapter { 32 | @Autowired 33 | private LineBotServerInterceptor lineBotServerInterceptor; 34 | @Autowired 35 | private LineBotServerArgumentProcessor lineBotServerArgumentProcessor; 36 | 37 | @Override 38 | public void addInterceptors(InterceptorRegistry registry) { 39 | registry.addInterceptor(lineBotServerInterceptor); 40 | } 41 | 42 | @Override 43 | public void addArgumentResolvers(List argumentResolvers) { 44 | argumentResolvers.add(lineBotServerArgumentProcessor); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /line-bot-model/src/test/java/com/linecorp/bot/model/message/ImagemapMessageTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | 21 | import java.util.Collections; 22 | 23 | import org.junit.Test; 24 | 25 | import com.fasterxml.jackson.core.JsonProcessingException; 26 | import com.fasterxml.jackson.databind.ObjectMapper; 27 | 28 | import com.linecorp.bot.model.message.imagemap.ImagemapArea; 29 | import com.linecorp.bot.model.message.imagemap.ImagemapBaseSize; 30 | import com.linecorp.bot.model.message.imagemap.MessageImagemapAction; 31 | import com.linecorp.bot.model.testutil.TestUtil; 32 | 33 | public class ImagemapMessageTest { 34 | @Test 35 | public void test() throws JsonProcessingException { 36 | ObjectMapper objectMapper = TestUtil.objectMapperWithProductionConfiguration(false); 37 | ImagemapMessage imagemapMessage = new ImagemapMessage( 38 | "https://example.com", "hoge", 39 | new ImagemapBaseSize(1040, 1040), 40 | Collections.singletonList( 41 | new MessageImagemapAction("hoge", 42 | new ImagemapArea(0, 0, 20, 20)))); 43 | 44 | String s = objectMapper.writeValueAsString(imagemapMessage); 45 | assertThat(s).contains("\"type\":\"imagemap\""); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/message/LocationMessageContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.message; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.annotation.JsonTypeName; 22 | 23 | import lombok.Value; 24 | 25 | /** 26 | * Message content for location type. 27 | */ 28 | @Value 29 | @JsonTypeName("location") 30 | public class LocationMessageContent implements MessageContent { 31 | private final String id; 32 | 33 | /** 34 | * Title 35 | */ 36 | private final String title; 37 | 38 | /** 39 | * Address 40 | */ 41 | private final String address; 42 | 43 | /** 44 | * Latitude 45 | */ 46 | private final double latitude; 47 | 48 | /** 49 | * Longitude 50 | */ 51 | private final double longitude; 52 | 53 | @JsonCreator 54 | public LocationMessageContent( 55 | @JsonProperty("id") String id, 56 | @JsonProperty("title") String title, 57 | @JsonProperty("address") String address, 58 | @JsonProperty("latitude") Double latitude, 59 | @JsonProperty("longitude") Double longitude) { 60 | this.id = id; 61 | this.title = title; 62 | this.address = address; 63 | this.latitude = latitude; 64 | this.longitude = longitude; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /sample-spring-boot-echo/README.md: -------------------------------------------------------------------------------- 1 | # sample-spring-boot-echo 2 | 3 | sample-spring-boot-echo is a tiny sample bot application based on Spring Boot. 4 | 5 | ## Usage 6 | 7 | Run this sample bot using Gradle. 8 | 9 | ../gradlew bootRun -Dline.bot.channelToken=YOUR_CHANNEL_TOKEN \ 10 | -Dline.bot.channelSecret=YOUR_CHANNEL_SECRET 11 | 12 | or if you finished create `src/main/resources/application.yml` file based on `src/main/resources/application-template.yml`. You can start configured web server just hitting 13 | 14 | ../gradlew bootRun 15 | 16 | You need to pass the following options. 17 | 18 | * line.bot.channelToken: Your Channel access token 19 | * line.bot.channelSecret: Your Channel secret 20 | 21 | For more information about configuration way, refer [Spring Boot Reference - 24. Externalized Configuration](https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html). 22 | 23 | ## Deploy on Heroku 24 | 25 | Deploy this module on Heroku. 26 | 27 | ### Step 1 28 | 29 | Get the Channel access token and Channel secret from the Channel Console. 30 | 31 | 32 | 33 | ### Step 2 34 | 35 | Tap the deploy button. 36 | 37 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/line/line-bot-sdk-java) 38 | 39 | ### Step 3 40 | 41 | Fill in the form and run your instance. 42 | 43 | 44 | 45 | ### Step 4 46 | 47 | Tap the **Manage App** button and copy the name of your Heroku instance. 48 | 49 | 50 | 51 | ### Step 5 52 | 53 | Set the webhook URL for your Channel on the Channel Console using the following URL: 54 | `https://${YOUR_HEROKU_APP_NAME}.herokuapp.com/callback` 55 | 56 | 57 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/BeaconEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event; 18 | 19 | import java.time.Instant; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.annotation.JsonTypeName; 24 | 25 | import com.linecorp.bot.model.event.beacon.BeaconContent; 26 | import com.linecorp.bot.model.event.source.Source; 27 | 28 | import lombok.Value; 29 | 30 | /** 31 | * Event object for when a user detects a LINE Beacon. You can reply to beacon events. 32 | */ 33 | @Value 34 | @JsonTypeName("beacon") 35 | public class BeaconEvent implements Event, ReplyEvent { 36 | /** 37 | * Token for replying to this event 38 | */ 39 | private final String replyToken; 40 | 41 | /** 42 | * JSON object which contains the source of the event 43 | */ 44 | private final Source source; 45 | 46 | /** 47 | * Content of the beacon event. 48 | */ 49 | private final BeaconContent beacon; 50 | 51 | /** 52 | * Time of the event 53 | */ 54 | private final Instant timestamp; 55 | 56 | @JsonCreator 57 | public BeaconEvent( 58 | @JsonProperty("replyToken") String replyToken, 59 | @JsonProperty("source") Source source, 60 | @JsonProperty("timestamp") Instant timestamp, 61 | @JsonProperty("beacon") BeaconContent beacon 62 | ) { 63 | this.replyToken = replyToken; 64 | this.source = source; 65 | this.timestamp = timestamp; 66 | this.beacon = beacon; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/MessageEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event; 18 | 19 | import java.time.Instant; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.annotation.JsonTypeName; 24 | 25 | import com.linecorp.bot.model.event.message.MessageContent; 26 | import com.linecorp.bot.model.event.source.Source; 27 | 28 | import lombok.Value; 29 | 30 | /** 31 | * Event object which contains the sent message. 32 | * The message field contains a message object which corresponds with the message type. You can reply to message events. 33 | */ 34 | @Value 35 | @JsonTypeName("message") 36 | public class MessageEvent implements Event, ReplyEvent { 37 | /** 38 | * Token for replying to this event 39 | */ 40 | private final String replyToken; 41 | 42 | /** 43 | * JSON object which contains the source of the event 44 | */ 45 | private final Source source; 46 | 47 | /** 48 | * Message body 49 | */ 50 | private final T message; 51 | 52 | /** 53 | * Time of the event 54 | */ 55 | private final Instant timestamp; 56 | 57 | @JsonCreator 58 | public MessageEvent( 59 | @JsonProperty("replyToken") String replyToken, 60 | @JsonProperty("source") Source source, 61 | @JsonProperty("message") T message, 62 | @JsonProperty("timestamp") Instant timestamp) { 63 | this.replyToken = replyToken; 64 | this.source = source; 65 | this.message = message; 66 | this.timestamp = timestamp; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/PostbackEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event; 18 | 19 | import java.time.Instant; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.annotation.JsonTypeName; 24 | 25 | import com.linecorp.bot.model.event.postback.PostbackContent; 26 | import com.linecorp.bot.model.event.source.Source; 27 | 28 | import lombok.Value; 29 | 30 | /** 31 | * Event object for when a user performs an action on a template message which initiates a postback. You can reply to postback events. 32 | */ 33 | @Value 34 | @JsonTypeName("postback") 35 | public class PostbackEvent implements Event, ReplyEvent { 36 | /** 37 | * Token for replying to this event 38 | */ 39 | private final String replyToken; 40 | 41 | /** 42 | * JSON object which contains the source of the event 43 | */ 44 | private final Source source; 45 | 46 | /** 47 | * Content of the postback event. 48 | */ 49 | private final PostbackContent postbackContent; 50 | 51 | /** 52 | * Time of the event 53 | */ 54 | private final Instant timestamp; 55 | 56 | @JsonCreator 57 | public PostbackEvent( 58 | @JsonProperty("replyToken") String replyToken, 59 | @JsonProperty("source") Source source, 60 | @JsonProperty("postback") PostbackContent postbackContent, 61 | @JsonProperty("timestamp") Instant timestamp) { 62 | this.replyToken = replyToken; 63 | this.source = source; 64 | this.postbackContent = postbackContent; 65 | this.timestamp = timestamp; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /line-bot-spring-boot/src/main/java/com/linecorp/bot/spring/boot/support/LineBotServerArgumentProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.spring.boot.support; 18 | 19 | import javax.servlet.http.HttpServletRequest; 20 | 21 | import org.springframework.core.MethodParameter; 22 | import org.springframework.stereotype.Component; 23 | import org.springframework.web.bind.support.WebDataBinderFactory; 24 | import org.springframework.web.context.request.NativeWebRequest; 25 | import org.springframework.web.context.request.RequestAttributes; 26 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 27 | import org.springframework.web.method.support.ModelAndViewContainer; 28 | 29 | import com.linecorp.bot.model.event.CallbackRequest; 30 | import com.linecorp.bot.spring.boot.annotation.LineBotMessages; 31 | 32 | @Component 33 | public class LineBotServerArgumentProcessor implements HandlerMethodArgumentResolver { 34 | private static final String PROPERTY_NAME = "com.linecorp.bot.spring.callbackRequest"; 35 | 36 | @Override 37 | public boolean supportsParameter(MethodParameter parameter) { 38 | return parameter.hasParameterAnnotation(LineBotMessages.class); 39 | } 40 | 41 | @Override 42 | public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, 43 | NativeWebRequest webRequest, WebDataBinderFactory binderFactory) 44 | throws Exception { 45 | return webRequest.getAttribute(PROPERTY_NAME, RequestAttributes.SCOPE_REQUEST); 46 | } 47 | 48 | public static void setValue(HttpServletRequest request, CallbackRequest callbackRequest) { 49 | request.setAttribute(PROPERTY_NAME, callbackRequest.getEvents()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /line-bot-model/src/test/java/com/linecorp/bot/model/event/ReplyEventTest.java: -------------------------------------------------------------------------------- 1 | package com.linecorp.bot.model.event; 2 | 3 | import static java.util.stream.Collectors.toList; 4 | import static org.assertj.core.api.Assertions.assertThat; 5 | 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.springframework.beans.factory.config.BeanDefinition; 10 | import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; 11 | import org.springframework.util.ClassUtils; 12 | 13 | import com.google.common.base.Preconditions; 14 | 15 | import lombok.extern.slf4j.Slf4j; 16 | 17 | @Slf4j 18 | public class ReplyEventTest { 19 | @Test 20 | public void eventWithReplyTokenShouldBeImplementReplySupportTest() { 21 | final List> eventClasses = getAllEventClass(); 22 | Preconditions.checkState(!eventClasses.isEmpty(), "Event classes are empty. Maybe scanning bug."); 23 | 24 | log.info("eventClasses = {}", eventClasses); 25 | 26 | for (Class eventClass : eventClasses) { 27 | final boolean hasReplyTokenMethod = ClassUtils.hasMethod(eventClass, "getReplyToken"); 28 | 29 | if (hasReplyTokenMethod) { 30 | assertThat(ReplyEvent.class) 31 | .isAssignableFrom(eventClass); 32 | } 33 | } 34 | } 35 | 36 | private static List> getAllEventClass() { 37 | ClassPathScanningCandidateComponentProvider scanningProvider = 38 | new ClassPathScanningCandidateComponentProvider(false); 39 | scanningProvider 40 | .addIncludeFilter((metadataReader, metadataReaderFactory) -> true); 41 | 42 | return scanningProvider.findCandidateComponents(Event.class.getPackage().getName()) 43 | .stream() 44 | .map(BeanDefinition::getBeanClassName) 45 | .map(className -> { 46 | try { 47 | return (Class) Class.forName(className); 48 | } catch (ClassNotFoundException e) { 49 | throw new RuntimeException(e); 50 | } 51 | }) 52 | .filter(Event.class::isAssignableFrom) 53 | .collect(toList()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /line-bot-api-client/src/test/java/com/linecorp/bot/client/LineSignatureValidatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | 21 | import java.nio.charset.StandardCharsets; 22 | 23 | import org.junit.Test; 24 | import org.springframework.util.Base64Utils; 25 | 26 | public class LineSignatureValidatorTest { 27 | private static final String channelSecret = "SECRET"; 28 | 29 | @Test 30 | public void validateSignature() throws Exception { 31 | LineSignatureValidator lineSignatureValidator = new LineSignatureValidator( 32 | channelSecret.getBytes(StandardCharsets.UTF_8)); 33 | 34 | String httpRequestBody = "{}"; 35 | assertThat(lineSignatureValidator 36 | .validateSignature(httpRequestBody.getBytes(StandardCharsets.UTF_8), 37 | "3q8QXTAGaey18yL8FWTqdVlbMr6hcuNvM4tefa0o9nA=")) 38 | .isTrue(); 39 | assertThat(lineSignatureValidator 40 | .validateSignature(httpRequestBody.getBytes(StandardCharsets.UTF_8), 41 | "596359635963")) 42 | .isFalse(); 43 | } 44 | 45 | @Test 46 | public void generateSignature() throws Exception { 47 | LineSignatureValidator lineSignatureValidator = new LineSignatureValidator( 48 | channelSecret.getBytes(StandardCharsets.UTF_8)); 49 | 50 | String httpRequestBody = "{}"; 51 | byte[] headerSignature = lineSignatureValidator 52 | .generateSignature(httpRequestBody.getBytes(StandardCharsets.UTF_8)); 53 | 54 | assertThat(Base64Utils.encodeToString(headerSignature)) 55 | .isEqualTo("3q8QXTAGaey18yL8FWTqdVlbMr6hcuNvM4tefa0o9nA="); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/event/beacon/BeaconContentUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.event.beacon; 18 | 19 | final class BeaconContentUtil { 20 | private BeaconContentUtil() { 21 | throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); 22 | } 23 | 24 | private static final char[] HEX_CODE = 25 | { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; 26 | 27 | /** 28 | * @throws IllegalArgumentException occurred when arguments is not null and illegal hex string. 29 | */ 30 | static byte[] parseBytesOrNull(final String deviceMessageAsHex) { 31 | if (deviceMessageAsHex == null) { 32 | return null; 33 | } 34 | 35 | final int length = deviceMessageAsHex.length(); 36 | final int resultSize = length / 2; 37 | 38 | if (length % 2 != 0) { 39 | throw new IllegalArgumentException("hex string needs to be even-length: " + deviceMessageAsHex); 40 | } 41 | 42 | final byte[] bytes = new byte[resultSize]; 43 | 44 | for (int pos = 0; pos < resultSize; pos++) { 45 | bytes[pos] = (byte) Integer.parseInt(deviceMessageAsHex.substring(pos * 2, pos * 2 + 2), 16); 46 | // Byte.parseByte doesn't support >= 0x80. 47 | } 48 | 49 | return bytes; 50 | } 51 | 52 | static String printHexBinary(final byte[] deviceMessage) { 53 | if (deviceMessage == null) { 54 | return null; 55 | } 56 | 57 | final StringBuilder sb = new StringBuilder(deviceMessage.length * 2); 58 | 59 | for (byte byteValue : deviceMessage) { 60 | final int intValue = Byte.toUnsignedInt(byteValue); 61 | sb.append(HEX_CODE[intValue >>> 4]); 62 | sb.append(HEX_CODE[intValue & 0xf]); 63 | } 64 | 65 | return sb.toString(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /line-bot-model/src/test/java/com/linecorp/bot/model/error/ErrorResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.error; 18 | 19 | import static java.lang.ClassLoader.getSystemResourceAsStream; 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | 22 | import java.io.IOException; 23 | 24 | import org.junit.Test; 25 | 26 | import com.fasterxml.jackson.databind.InjectableValues; 27 | import com.fasterxml.jackson.databind.ObjectMapper; 28 | 29 | public class ErrorResponseTest { 30 | private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() 31 | .setInjectableValues(new InjectableValues.Std().addValue("requestId", "requestId")); 32 | 33 | @Test 34 | public void simpleErrorResponseTest() throws IOException { 35 | // Do 36 | final ErrorResponse result = OBJECT_MAPPER 37 | .readValue(getSystemResourceAsStream("error/error401.json"), 38 | ErrorResponse.class); 39 | 40 | // Verify 41 | assertThat(result.getMessage()).contains("Authentication failed"); 42 | assertThat(result.getDetails()).isNotNull().isEmpty(); 43 | } 44 | 45 | @Test 46 | public void complexErrorResponseTest() throws IOException { 47 | // Do 48 | final ErrorResponse result = OBJECT_MAPPER 49 | .readValue(getSystemResourceAsStream("error/error_with_detail.json"), 50 | ErrorResponse.class); 51 | 52 | // Verify 53 | assertThat(result.getMessage()).isEqualTo("The request body has 2 error(s)"); 54 | assertThat(result.getDetails()).containsExactly( 55 | new ErrorDetail("May not be empty", 56 | "messages[0].text"), 57 | new ErrorDetail("Must be one of the following values: " + 58 | "[text, image, video, audio, location, sticker, richmessage, template, imagemap]", 59 | "messages[1].type")); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/template/CarouselTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.template; 18 | 19 | import java.util.List; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.annotation.JsonTypeName; 24 | 25 | import lombok.AccessLevel; 26 | import lombok.AllArgsConstructor; 27 | import lombok.Builder; 28 | import lombok.Value; 29 | 30 | /** 31 | * Template message with multiple columns which can be cycled like a carousel. 32 | * 33 | * @see CarouselTemplateBuilder 34 | */ 35 | @Value 36 | @Builder 37 | @AllArgsConstructor(access = AccessLevel.PRIVATE) 38 | @JsonTypeName("carousel") 39 | public class CarouselTemplate implements Template { 40 | /** 41 | * List of columns(Max: 5) 42 | */ 43 | private final List columns; 44 | 45 | /** 46 | * Aspect ratio of the image. Specify one of the following values: 47 | * 48 | *
    49 | *
  • rectangle: 1.51:1
  • 50 | *
  • square: 1:1
  • 51 | *
52 | * 53 | * The default value is {@code rectangle}. 54 | */ 55 | private final String imageAspectRatio; 56 | 57 | /** 58 | * Size of the image. Specify one of the following values: 59 | * 60 | *
    61 | *
  • cover: The image fills the entire image area. Parts of the image that do not fit in the area are not displayed.
  • 62 | *
  • contain: The entire image is displayed in the image area. A background is displayed in the unused areas to the left and right of vertical images and in the areas above and below horizontal images.
  • 63 | *
64 | * 65 | * The default value is {@code cover}. 66 | */ 67 | private final String imageSize; 68 | 69 | @JsonCreator 70 | public CarouselTemplate(@JsonProperty("columns") List columns) { 71 | this.columns = columns; 72 | this.imageAspectRatio = null; 73 | this.imageSize = null; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /line-bot-api-client/src/test/java/com/linecorp/bot/client/AbstractWiremockTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client; 18 | 19 | import org.junit.After; 20 | import org.junit.Before; 21 | import org.slf4j.bridge.SLF4JBridgeHandler; 22 | 23 | import com.fasterxml.jackson.databind.ObjectMapper; 24 | import com.fasterxml.jackson.databind.ObjectWriter; 25 | 26 | import com.linecorp.bot.model.error.ErrorResponse; 27 | 28 | import lombok.SneakyThrows; 29 | import okhttp3.mockwebserver.MockResponse; 30 | import okhttp3.mockwebserver.MockWebServer; 31 | 32 | public abstract class AbstractWiremockTest { 33 | public static final int ASYNC_TEST_TIMEOUT = 1_000; 34 | private static final ObjectWriter ERROR_RESPONSE_READER = new ObjectMapper().writerFor(ErrorResponse.class); 35 | 36 | static { 37 | SLF4JBridgeHandler.install(); 38 | SLF4JBridgeHandler.removeHandlersForRootLogger(); 39 | } 40 | 41 | protected MockWebServer mockWebServer; 42 | protected LineMessagingClient lineMessagingClient; 43 | 44 | @Before 45 | public void setUpWireMock() { 46 | mockWebServer = new MockWebServer(); 47 | lineMessagingClient = createLineMessagingClient(mockWebServer); 48 | } 49 | 50 | @After 51 | public void shutDownWireMock() throws Exception { 52 | mockWebServer.shutdown(); 53 | } 54 | 55 | @SneakyThrows 56 | public void mocking(final int responseCode, final ErrorResponse errorResponse) { 57 | mockWebServer 58 | .enqueue(new MockResponse() 59 | .setResponseCode(responseCode) 60 | .setBody(ERROR_RESPONSE_READER.writeValueAsString(errorResponse))); 61 | } 62 | 63 | protected LineMessagingClientImpl createLineMessagingClient(final MockWebServer mockWebServer) { 64 | LineMessagingService lineMessagingService = 65 | LineMessagingServiceBuilder.create("token") 66 | .apiEndPoint("http://localhost:" + mockWebServer.getPort()) 67 | .build(); 68 | return new LineMessagingClientImpl(lineMessagingService); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/action/PostbackAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.action; 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | import com.fasterxml.jackson.annotation.JsonInclude; 22 | import com.fasterxml.jackson.annotation.JsonInclude.Include; 23 | import com.fasterxml.jackson.annotation.JsonProperty; 24 | import com.fasterxml.jackson.annotation.JsonTypeName; 25 | 26 | import lombok.Value; 27 | 28 | /** 29 | *

30 | * When this action is tapped, a postback event is returned via webhook with the specified string in the data field. 31 | *

32 | * 33 | *

34 | * If you have included the text field, the string in the text field is sent as a message from the user. 35 | *

36 | */ 37 | @Value 38 | @JsonIgnoreProperties(ignoreUnknown = true) 39 | @JsonTypeName("postback") 40 | @JsonInclude(Include.NON_NULL) 41 | public class PostbackAction implements Action { 42 | /** 43 | * Label for the action
44 | * Max: 20 characters 45 | */ 46 | private final String label; 47 | 48 | /** 49 | * String returned via webhook in the postback.data property of the postback event
50 | * Max: 300 characters 51 | */ 52 | private final String data; 53 | 54 | /** 55 | * Text sent when the action is performed
56 | * Max: 300 characters 57 | */ 58 | private final String text; 59 | 60 | /** 61 | * Create new instance. 62 | * @param label Label for the action. Max: 20 characters. 63 | * @param data String returned via webhook in the postback.data property of the postback event. 64 | * Max: 300 characters. 65 | * @param text text message (optional) 66 | */ 67 | @JsonCreator 68 | public PostbackAction( 69 | @JsonProperty("label") String label, 70 | @JsonProperty("data") String data, 71 | @JsonProperty("text") String text) { 72 | this.label = label; 73 | this.data = data; 74 | this.text = text; 75 | } 76 | 77 | public PostbackAction(String label, String data) { 78 | this(label, data, null); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /line-bot-api-client/src/test/java/com/linecorp/bot/client/HeaderInterceptorWireMockTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client; 18 | 19 | import static java.util.Collections.singletonList; 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | import static org.mockito.Mockito.when; 22 | 23 | import org.junit.Rule; 24 | import org.junit.Test; 25 | import org.mockito.Mock; 26 | import org.mockito.junit.MockitoJUnit; 27 | import org.mockito.junit.MockitoRule; 28 | 29 | import okhttp3.mockwebserver.MockWebServer; 30 | import okhttp3.mockwebserver.RecordedRequest; 31 | 32 | public class HeaderInterceptorWireMockTest extends AbstractWiremockTest { 33 | @Rule 34 | public final MockitoRule mockitoRule = MockitoJUnit.rule(); 35 | 36 | @Mock 37 | ChannelTokenSupplier channelTokenSupplier; 38 | 39 | @Test(timeout = ASYNC_TEST_TIMEOUT) 40 | public void forChannelTokenSupplier() throws Exception { 41 | // Do 42 | when(channelTokenSupplier.get()).thenReturn("1st"); 43 | lineMessagingClient.getMessageContent("TEST"); 44 | 45 | // Verify 46 | final RecordedRequest request1st = mockWebServer.takeRequest(); 47 | assertThat(request1st.getHeaders().toMultimap()) 48 | .containsEntry("Authorization", singletonList("Bearer 1st")); 49 | 50 | // Do again with another channel token. 51 | when(channelTokenSupplier.get()).thenReturn("2nd"); 52 | lineMessagingClient.getMessageContent("TEST"); 53 | 54 | // Verify 55 | final RecordedRequest request2nd = mockWebServer.takeRequest(); 56 | assertThat(request2nd.getHeaders().toMultimap()) 57 | .containsEntry("Authorization", singletonList("Bearer 2nd")); 58 | } 59 | 60 | @Override 61 | protected LineMessagingClientImpl createLineMessagingClient(final MockWebServer mockWebServer) { 62 | LineMessagingService lineMessagingService = 63 | LineMessagingServiceBuilder.create(channelTokenSupplier) 64 | .apiEndPoint("http://localhost:" + mockWebServer.getPort()) 65 | .build(); 66 | return new LineMessagingClientImpl(lineMessagingService); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /line-bot-model/src/main/java/com/linecorp/bot/model/message/template/CarouselColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.message.template; 18 | 19 | import java.util.Collections; 20 | import java.util.List; 21 | 22 | import com.fasterxml.jackson.annotation.JsonCreator; 23 | import com.fasterxml.jackson.annotation.JsonProperty; 24 | 25 | import com.linecorp.bot.model.action.Action; 26 | 27 | import lombok.AccessLevel; 28 | import lombok.AllArgsConstructor; 29 | import lombok.Builder; 30 | import lombok.Value; 31 | 32 | /** 33 | * Column object for carousel template 34 | * 35 | * @see CarouselColumnBuilder 36 | */ 37 | @Value 38 | @Builder 39 | @AllArgsConstructor(access = AccessLevel.PUBLIC) 40 | public class CarouselColumn { 41 | /** 42 | * Image URL 43 | *
    44 | *
  • HTTPS
  • 45 | *
  • JPEG or PNG
  • 46 | *
  • Aspect ratio: 1:1.51
  • 47 | *
  • Max width: 1024px
  • 48 | *
  • Max: 1 MB
  • 49 | *
50 | */ 51 | private final String thumbnailImageUrl; 52 | 53 | /** 54 | * Background color of image. 55 | * 56 | *

Specify a RGB color value. The default value is #FFFFFF (white). 57 | */ 58 | private final String imageBackgroundColor; 59 | 60 | /** 61 | * Title (Max: 40 characters) 62 | */ 63 | private final String title; 64 | 65 | /** 66 | * Message text
67 | * Max: 120 characters (no image or title)
68 | * Max: 60 characters (message with an image or title) 69 | */ 70 | private final String text; 71 | 72 | /** 73 | * Action when tapped(Max: 3) 74 | */ 75 | private final List actions; 76 | 77 | @JsonCreator 78 | public CarouselColumn( 79 | @JsonProperty("thumbnailImageUrl") String thumbnailImageUrl, 80 | @JsonProperty("title") String title, 81 | @JsonProperty("text") String text, 82 | @JsonProperty("actions") List actions) { 83 | this.thumbnailImageUrl = thumbnailImageUrl; 84 | this.title = title; 85 | this.text = text; 86 | this.actions = actions != null ? actions : Collections.emptyList(); 87 | this.imageBackgroundColor = null; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /line-bot-spring-boot/src/main/java/com/linecorp/bot/spring/boot/BotPropertiesValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.spring.boot; 18 | 19 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.Target; 25 | 26 | import javax.validation.Constraint; 27 | import javax.validation.ConstraintValidator; 28 | import javax.validation.ConstraintValidatorContext; 29 | import javax.validation.Payload; 30 | 31 | import com.linecorp.bot.spring.boot.BotPropertiesValidator.ValidBotProperties; 32 | 33 | public class BotPropertiesValidator implements ConstraintValidator { 34 | @Target({ ElementType.TYPE }) 35 | @Retention(RUNTIME) 36 | @Documented 37 | @Constraint(validatedBy = { BotPropertiesValidator.class }) 38 | public @interface ValidBotProperties { 39 | Class[] groups() default {}; 40 | 41 | String message() default ""; 42 | 43 | Class[] payload() default {}; 44 | 45 | } 46 | 47 | @Override 48 | public void initialize(ValidBotProperties constraintAnnotation) { 49 | } 50 | 51 | @Override 52 | public boolean isValid(LineBotProperties value, ConstraintValidatorContext context) { 53 | switch (value.getChannelTokenSupplyMode()) { 54 | case FIXED: 55 | if (value.getChannelToken() != null) { 56 | return true; 57 | } else { 58 | context.buildConstraintViolationWithTemplate("channelToken is null") 59 | .addPropertyNode("channelToken") 60 | .addConstraintViolation(); 61 | return false; 62 | } 63 | case SUPPLIER: 64 | if (value.getChannelToken() == null) { 65 | return true; 66 | } else { 67 | context.buildConstraintViolationWithTemplate( 68 | "channelToken should be null if channelTokenSupplyMode = SUPPLIER") 69 | .addPropertyNode("channelToken") 70 | .addConstraintViolation(); 71 | return false; 72 | } 73 | } 74 | throw new IllegalStateException("Not implemented channelTokenSupplyMode."); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /line-bot-api-client/src/main/java/com/linecorp/bot/client/LineSignatureValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client; 18 | 19 | import java.security.InvalidKeyException; 20 | import java.security.MessageDigest; 21 | import java.security.NoSuchAlgorithmException; 22 | import java.util.Base64; 23 | 24 | import javax.crypto.Mac; 25 | import javax.crypto.spec.SecretKeySpec; 26 | 27 | import lombok.NonNull; 28 | import lombok.ToString; 29 | 30 | /* 31 | * This class validates value of the `X-LINE-Signature` header. 32 | */ 33 | @ToString 34 | public class LineSignatureValidator { 35 | private static final String HASH_ALGORITHM = "HmacSHA256"; 36 | private final SecretKeySpec secretKeySpec; 37 | 38 | /** 39 | * Create new instance with channel secret. 40 | */ 41 | public LineSignatureValidator(byte[] channelSecret) { 42 | this.secretKeySpec = new SecretKeySpec(channelSecret, HASH_ALGORITHM); 43 | } 44 | 45 | /** 46 | * Validate signature. 47 | * 48 | * @param content Body of the http request in byte array. 49 | * @param headerSignature Signature value from `X-LINE-Signature` HTTP header 50 | * @return True if headerSignature matches signature of the content. False otherwise. 51 | */ 52 | public boolean validateSignature(@NonNull byte[] content, @NonNull String headerSignature) { 53 | final byte[] signature = generateSignature(content); 54 | final byte[] decodeHeaderSignature = Base64.getDecoder().decode(headerSignature); 55 | return MessageDigest.isEqual(decodeHeaderSignature, signature); 56 | } 57 | 58 | /** 59 | * Generate signature value. 60 | * 61 | * @param content Body of the http request. 62 | * @return generated signature value. 63 | */ 64 | public byte[] generateSignature(@NonNull byte[] content) { 65 | try { 66 | Mac mac = Mac.getInstance(HASH_ALGORITHM); 67 | mac.init(secretKeySpec); 68 | return mac.doFinal(content); 69 | } catch (NoSuchAlgorithmException | InvalidKeyException e) { 70 | // "HmacSHA256" is always supported in Java 8 platform. 71 | // (see https://docs.oracle.com/javase/8/docs/api/javax/crypto/Mac.html) 72 | // All valid-SecretKeySpec-instance are not InvalidKey. 73 | // (because the key for HmacSHA256 can be of any length. see RFC2104) 74 | throw new IllegalStateException(e); 75 | } 76 | } 77 | 78 | } 79 | 80 | -------------------------------------------------------------------------------- /line-bot-api-client/src/test/java/com/linecorp/bot/client/CallbackAdaptorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.client; 18 | 19 | import static okhttp3.MediaType.parse; 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | import static org.mockito.Mockito.mock; 22 | import static org.mockito.Mockito.when; 23 | 24 | import org.junit.Before; 25 | import org.junit.Rule; 26 | import org.junit.Test; 27 | import org.junit.rules.Timeout; 28 | import org.mockito.Mock; 29 | import org.mockito.junit.MockitoJUnit; 30 | import org.mockito.junit.MockitoRule; 31 | 32 | import com.linecorp.bot.client.LineMessagingClientImpl.CallbackAdaptor; 33 | import com.linecorp.bot.client.exception.GeneralLineMessagingException; 34 | 35 | import okhttp3.ResponseBody; 36 | import retrofit2.Call; 37 | import retrofit2.Response; 38 | 39 | public class CallbackAdaptorTest { 40 | private CallbackAdaptor target; 41 | 42 | @Rule 43 | public final MockitoRule mockitoRule = MockitoJUnit.rule(); 44 | 45 | @Rule 46 | public final Timeout timeoutRule = Timeout.seconds(1); 47 | 48 | @Mock 49 | private Call call; 50 | 51 | @Before 52 | public void setUp() throws Exception { 53 | target = new CallbackAdaptor<>(); 54 | } 55 | 56 | @Test 57 | public void onResponseSuccessfullyTest() throws Exception { 58 | final Object value = new Object(); 59 | Response response = Response.success(value); 60 | 61 | // Do 62 | target.onResponse(call, response); 63 | 64 | // Verify 65 | assertThat(target).isCompletedWithValue(value); 66 | } 67 | 68 | @Test 69 | public void onResponseWithErrorTest() throws Exception { 70 | Response response = 71 | Response.error(400, ResponseBody.create(parse("application/json"), "{}")); 72 | 73 | // Do 74 | target.onResponse(call, response); 75 | 76 | // Verify 77 | assertThat(target).isCompletedExceptionally(); 78 | } 79 | 80 | @Test 81 | public void onFailureTest() throws Exception { 82 | Throwable t = mock(Throwable.class); 83 | when(t.getMessage()).thenReturn("Message"); 84 | 85 | // Do 86 | target.onFailure(call, t); 87 | 88 | // Verify 89 | assertThat(target).isCompletedExceptionally(); 90 | assertThat(target.handle((ignored, e) -> e).get()) 91 | .isInstanceOf(GeneralLineMessagingException.class) 92 | .hasMessageContaining("Message"); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /line-bot-model/src/test/java/com/linecorp/bot/model/profile/ProfileResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 LINE Corporation 3 | * 4 | * LINE Corporation licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.linecorp.bot.model.profile; 18 | 19 | import static java.lang.ClassLoader.getSystemResourceAsStream; 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | 25 | import org.junit.Test; 26 | 27 | import com.fasterxml.jackson.databind.DeserializationFeature; 28 | import com.fasterxml.jackson.databind.ObjectMapper; 29 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; 30 | 31 | public class ProfileResponseTest { 32 | @Test 33 | public void testProfile() throws IOException { 34 | try (InputStream resourceAsStream = getSystemResourceAsStream("user-profiles.json")) { 35 | ObjectMapper objectMapper = new ObjectMapper() 36 | .registerModule(new JavaTimeModule()) 37 | .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); 38 | 39 | final UserProfileResponse userProfileResponse = 40 | objectMapper.readValue(resourceAsStream, UserProfileResponse.class); 41 | 42 | assertThat(userProfileResponse.getDisplayName()).isEqualTo("Tester"); 43 | assertThat(userProfileResponse.getUserId()).isEqualTo("Uc6a5e7b3d4d08c33dd8d530fb3c02762"); 44 | assertThat(userProfileResponse.getPictureUrl()).isEqualTo("https://example.com/picture.png"); 45 | assertThat(userProfileResponse.getStatusMessage()).isEqualTo("Movie"); 46 | } 47 | } 48 | 49 | @Test 50 | public void testMemberProfile() throws IOException { 51 | try (InputStream resourceAsStream = getSystemResourceAsStream("user-profiles_member.json")) { 52 | ObjectMapper objectMapper = new ObjectMapper() 53 | .registerModule(new JavaTimeModule()) 54 | .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); 55 | 56 | final UserProfileResponse userProfileResponse = 57 | objectMapper.readValue(resourceAsStream, UserProfileResponse.class); 58 | 59 | assertThat(userProfileResponse.getDisplayName()).isEqualTo("Tester"); 60 | assertThat(userProfileResponse.getUserId()).isEqualTo("Uc6a5e7b3d4d08c33dd8d530fb3c02762"); 61 | assertThat(userProfileResponse.getPictureUrl()).isEqualTo("https://example.com/picture.png"); 62 | assertThat(userProfileResponse.getStatusMessage()).isNull(); 63 | } 64 | } 65 | } 66 | --------------------------------------------------------------------------------