Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@
import com.linecorp.bot.model.group.GroupSummaryResponse;
import com.linecorp.bot.model.profile.MembersIdsResponse;
import com.linecorp.bot.model.profile.UserProfileResponse;
import com.linecorp.bot.model.request.TestWebhookEndpointRequest;
import com.linecorp.bot.model.response.BotApiResponse;
import com.linecorp.bot.model.response.BotInfoResponse;
import com.linecorp.bot.model.response.GetMessageEventResponse;
import com.linecorp.bot.model.response.GetNumberOfFollowersResponse;
import com.linecorp.bot.model.response.GetNumberOfMessageDeliveriesResponse;
import com.linecorp.bot.model.response.GetWebhookEndpointResponse;
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
import com.linecorp.bot.model.response.MessageQuotaResponse;
import com.linecorp.bot.model.response.NarrowcastProgressResponse;
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
import com.linecorp.bot.model.response.QuotaConsumptionResponse;
import com.linecorp.bot.model.response.TestWebhookEndpointResponse;
import com.linecorp.bot.model.response.demographics.GetFriendsDemographicsResponse;
import com.linecorp.bot.model.richmenu.RichMenu;
import com.linecorp.bot.model.richmenu.RichMenuIdResponse;
Expand Down Expand Up @@ -378,6 +381,20 @@ public interface LineMessagingClient {
*/
CompletableFuture<BotInfoResponse> getBotInfo();

/**
* Gets webhook endpoint information.
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-webhook-endpoint-information">Get webhook endpoint information</a>
*/
CompletableFuture<GetWebhookEndpointResponse> getWebhookEndpoint();

/**
* Tests webhook endpoint.
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#test-webhook-endpoint">Test webhook endpoint</a>
*/
CompletableFuture<TestWebhookEndpointResponse> testWebhookEndpoint(TestWebhookEndpointRequest request);

static LineMessagingClientBuilder builder(String channelToken) {
return builder(FixedChannelTokenSupplier.of(channelToken));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@
import com.linecorp.bot.model.group.GroupSummaryResponse;
import com.linecorp.bot.model.profile.MembersIdsResponse;
import com.linecorp.bot.model.profile.UserProfileResponse;
import com.linecorp.bot.model.request.TestWebhookEndpointRequest;
import com.linecorp.bot.model.response.BotApiResponse;
import com.linecorp.bot.model.response.BotInfoResponse;
import com.linecorp.bot.model.response.GetMessageEventResponse;
import com.linecorp.bot.model.response.GetNumberOfFollowersResponse;
import com.linecorp.bot.model.response.GetNumberOfMessageDeliveriesResponse;
import com.linecorp.bot.model.response.GetWebhookEndpointResponse;
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
import com.linecorp.bot.model.response.MessageQuotaResponse;
import com.linecorp.bot.model.response.NarrowcastProgressResponse;
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
import com.linecorp.bot.model.response.QuotaConsumptionResponse;
import com.linecorp.bot.model.response.TestWebhookEndpointResponse;
import com.linecorp.bot.model.response.demographics.GetFriendsDemographicsResponse;
import com.linecorp.bot.model.richmenu.RichMenu;
import com.linecorp.bot.model.richmenu.RichMenuBulkLinkRequest;
Expand Down Expand Up @@ -285,6 +288,17 @@ public CompletableFuture<BotInfoResponse> getBotInfo() {
return toFuture(retrofitImpl.getBotInfo());
}

@Override
public CompletableFuture<GetWebhookEndpointResponse> getWebhookEndpoint() {
return toFuture(retrofitImpl.getWebhookEndpoint());
}

@Override
public CompletableFuture<TestWebhookEndpointResponse> testWebhookEndpoint(
TestWebhookEndpointRequest request) {
return toFuture(retrofitImpl.testWebhookEndpoint(request));
}

// TODO: Extract this method.
static <T> CompletableFuture<T> toFuture(Call<T> callToWrap) {
final CallbackAdaptor<T> completableFuture = new CallbackAdaptor<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@
import com.linecorp.bot.model.group.GroupSummaryResponse;
import com.linecorp.bot.model.profile.MembersIdsResponse;
import com.linecorp.bot.model.profile.UserProfileResponse;
import com.linecorp.bot.model.request.TestWebhookEndpointRequest;
import com.linecorp.bot.model.response.BotInfoResponse;
import com.linecorp.bot.model.response.GetMessageEventResponse;
import com.linecorp.bot.model.response.GetNumberOfFollowersResponse;
import com.linecorp.bot.model.response.GetNumberOfMessageDeliveriesResponse;
import com.linecorp.bot.model.response.GetWebhookEndpointResponse;
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
import com.linecorp.bot.model.response.MessageQuotaResponse;
import com.linecorp.bot.model.response.NarrowcastProgressResponse;
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
import com.linecorp.bot.model.response.QuotaConsumptionResponse;
import com.linecorp.bot.model.response.TestWebhookEndpointResponse;
import com.linecorp.bot.model.response.demographics.GetFriendsDemographicsResponse;
import com.linecorp.bot.model.richmenu.RichMenu;
import com.linecorp.bot.model.richmenu.RichMenuBulkLinkRequest;
Expand Down Expand Up @@ -382,4 +385,10 @@ Call<Void> linkRichMenuToUser(
*/
@GET("v2/bot/info")
Call<BotInfoResponse> getBotInfo();

@GET("v2/bot/channel/webhook/endpoint")
Call<GetWebhookEndpointResponse> getWebhookEndpoint();

@POST("v2/bot/channel/webhook/test")
Call<TestWebhookEndpointResponse> testWebhookEndpoint(@Body TestWebhookEndpointRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.io.IOException;
import java.net.URI;
import java.time.Instant;
import java.util.Collections;

import org.junit.Rule;
Expand All @@ -54,17 +55,20 @@
import com.linecorp.bot.model.narrowcast.filter.GenderDemographicFilter.Gender;
import com.linecorp.bot.model.profile.MembersIdsResponse;
import com.linecorp.bot.model.profile.UserProfileResponse;
import com.linecorp.bot.model.request.TestWebhookEndpointRequest;
import com.linecorp.bot.model.response.BotApiResponse;
import com.linecorp.bot.model.response.BotInfoResponse;
import com.linecorp.bot.model.response.GetNumberOfFollowersResponse;
import com.linecorp.bot.model.response.GetNumberOfMessageDeliveriesResponse;
import com.linecorp.bot.model.response.GetWebhookEndpointResponse;
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
import com.linecorp.bot.model.response.MessageQuotaResponse;
import com.linecorp.bot.model.response.MessageQuotaResponse.QuotaType;
import com.linecorp.bot.model.response.NarrowcastProgressResponse;
import com.linecorp.bot.model.response.NarrowcastProgressResponse.Phase;
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
import com.linecorp.bot.model.response.QuotaConsumptionResponse;
import com.linecorp.bot.model.response.TestWebhookEndpointResponse;
import com.linecorp.bot.model.richmenu.RichMenu;
import com.linecorp.bot.model.richmenu.RichMenuBulkLinkRequest;
import com.linecorp.bot.model.richmenu.RichMenuBulkUnlinkRequest;
Expand Down Expand Up @@ -663,6 +667,39 @@ public void getBotInfo() throws Exception {
assertThat(actual).isEqualTo(response);
}

@Test
public void getWebhookEndpoint() throws Exception {
final GetWebhookEndpointResponse response = GetWebhookEndpointResponse
.builder()
.endpoint(URI.create("https://line.me/webhook"))
.active(true)
.build();
whenCall(retrofitMock.getWebhookEndpoint(), response);
final GetWebhookEndpointResponse actual = target.getWebhookEndpoint().get();
verify(retrofitMock, only()).getWebhookEndpoint();
assertThat(actual).isEqualTo(response);
}

@Test
public void testWebhookEndpoint() throws Exception {
final TestWebhookEndpointResponse response = TestWebhookEndpointResponse
.builder()
.success(true)
.timestamp(Instant.now())
.detail("abc")
.reason("def")
.statusCode(200)
.build();
final TestWebhookEndpointRequest request = TestWebhookEndpointRequest
.builder()
.endpoint(URI.create("http://example.com/my/great/endpoint"))
.build();
whenCall(retrofitMock.testWebhookEndpoint(request), response);
final TestWebhookEndpointResponse actual = target.testWebhookEndpoint(request).get();
verify(retrofitMock, only()).testWebhookEndpoint(request);
assertThat(actual).isEqualTo(response);
}

// Utility methods

private static <T> void whenCall(Call<T> call, T value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2020 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.linecorp.bot.model.request;

import java.net.URI;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

import com.linecorp.bot.model.request.TestWebhookEndpointRequest.TestWebhookEndpointRequestBuilder;

import lombok.Builder;
import lombok.Value;

@Value
@Builder
@JsonDeserialize(builder = TestWebhookEndpointRequestBuilder.class)
public class TestWebhookEndpointRequest {
/**
* A valid webhook URL. If {@literal null}, sends a test webhook event to a webhook endpoint that is already
* set to the channel.
*/
URI endpoint;

@JsonPOJOBuilder(withPrefix = "")
public static class TestWebhookEndpointRequestBuilder {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2020 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.linecorp.bot.model.response;

import java.net.URI;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

import com.linecorp.bot.model.response.GetWebhookEndpointResponse.GetWebhookEndpointResponseBuilder;

import lombok.Builder;
import lombok.Value;

@Value
@Builder
@JsonDeserialize(builder = GetWebhookEndpointResponseBuilder.class)
public class GetWebhookEndpointResponse {
/**
* Webhook URL.
*/
URI endpoint;

/*
* Webhook usage status. The LINE platform sends a webhook event to {@link #endpoint} only if
* {@literal true}.
*/
boolean active;

@JsonPOJOBuilder(withPrefix = "")
public static class GetWebhookEndpointResponseBuilder {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2020 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.linecorp.bot.model.response;

import java.time.Instant;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

import com.linecorp.bot.model.response.TestWebhookEndpointResponse.TestWebhookEndpointResponseBuilder;

import lombok.Builder;
import lombok.Value;

@Value
@Builder
@JsonDeserialize(builder = TestWebhookEndpointResponseBuilder.class)
public class TestWebhookEndpointResponse {
/**
* Result of the communication from the LINE platform to the webhook URL.
*/
boolean success;

/**
* Please refer to <a href="https://developers.line.biz/en/reference/messaging-api/#common-properties">
* Common Properties</a>.
*/
Instant timestamp;

/**
* The HTTP status code. If the webhook response isn't received, the status code is set to zero or a
* negative number.
*/
int statusCode;

/**
* Reason for the response.
*/
String reason;

/**
* Details of the response.
*/
String detail;

@JsonPOJOBuilder(withPrefix = "")
public static class TestWebhookEndpointResponseBuilder {
}
}
Loading