-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an ability to set callback from controller method
- Loading branch information
Showing
6 changed files
with
82 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/github/kshashov/telegram/handler/processor/ProcessedTelegramCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.github.kshashov.telegram.handler.processor; | ||
|
||
import com.pengrad.telegrambot.Callback; | ||
import com.pengrad.telegrambot.request.BaseRequest; | ||
import com.pengrad.telegrambot.response.BaseResponse; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.validation.constraints.NotNull; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Result of the Telegram request processing. Includes callback methods to handle Telegram response. | ||
*/ | ||
public class ProcessedTelegramCallback implements Callback<BaseRequest, BaseResponse> { | ||
private final BaseRequest request; | ||
private final Callback<BaseRequest, BaseResponse> nestedCallback; | ||
|
||
public ProcessedTelegramCallback(@NotNull BaseRequest request, @Nullable Callback<BaseRequest, BaseResponse> nestedCallback) { | ||
this.request = request; | ||
this.nestedCallback = nestedCallback; | ||
} | ||
|
||
public BaseRequest getRequest() { | ||
return request; | ||
} | ||
|
||
@Override | ||
public void onResponse(BaseRequest request, BaseResponse response) { | ||
if (nestedCallback == null) return; | ||
nestedCallback.onResponse(request, response); | ||
} | ||
|
||
@Override | ||
public void onFailure(BaseRequest request, IOException e) { | ||
if (nestedCallback == null) return; | ||
nestedCallback.onFailure(request, e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters