|
4 | 4 | import com.unblu.middleware.bots.service.DialogBotService; |
5 | 5 | import com.unblu.middleware.common.entity.ContextSpec; |
6 | 6 | import com.unblu.middleware.webhooks.annotation.UnbluWebhooks; |
7 | | -import com.unblu.middleware.webhooks.service.WebhookHandlerService; |
| 7 | +import com.unblu.middleware.webhooks.entity.WebhookHandlerOptions; |
| 8 | +import com.unblu.middleware.webhooks.service.WebhookHandler; |
8 | 9 | import com.unblu.webapi.jersey.v4.api.BotsApi; |
9 | 10 | import com.unblu.webapi.jersey.v4.invoker.ApiException; |
10 | 11 | import com.unblu.webapi.model.v4.*; |
|
16 | 17 | import org.springframework.stereotype.Service; |
17 | 18 | import reactor.core.publisher.Mono; |
18 | 19 |
|
19 | | -import static com.unblu.middleware.common.registry.RequestOrderSpec.canIgnoreOrder; |
20 | 20 | import static com.unblu.middleware.webhooks.entity.EventName.eventName; |
21 | 21 |
|
22 | 22 | @Service |
|
28 | 28 | }) |
29 | 29 | public class TestMiddlewareService implements ApplicationRunner { |
30 | 30 |
|
31 | | - private final WebhookHandlerService webhookHandlerService; |
| 31 | + private final WebhookHandler webhookHandler; |
32 | 32 | private final DialogBotService dialogBotService; |
33 | 33 | private final BotsApi botsApi; |
34 | 34 |
|
35 | 35 | @Override |
36 | 36 | public void run(ApplicationArguments args) { |
37 | 37 | // accept every onboarding offer |
38 | 38 | dialogBotService.acceptOnboardingOfferIf(_o -> Mono.just(true) |
39 | | - .doOnNext(_r -> log.info("Accepting as usual"))); |
| 39 | + .doOnNext(_r -> log.info("Accepting as usual"))); |
40 | 40 |
|
41 | 41 | // greet the user when a dialog is opened |
42 | 42 | dialogBotService.onDialogOpen(r -> |
43 | | - Mono.fromRunnable(() -> sendMessage(r.getDialogToken(), "Hello, I am a bot!"))); |
| 43 | + Mono.fromRunnable(() -> sendMessage(r.getDialogToken(), "Hello, I am a bot!"))); |
44 | 44 |
|
45 | 45 | // echo every message back to the user |
46 | 46 | dialogBotService.onDialogMessage(r -> |
47 | | - Mono.fromRunnable(() -> echoIfSentByVisitor(r))); |
| 47 | + Mono.fromRunnable(() -> echoIfSentByVisitor(r))); |
48 | 48 |
|
49 | 49 | // log every message sent anywhere using a webhook handler |
50 | | - webhookHandlerService.onWebhook(eventName("conversation.new_message"), ConversationNewMessageEvent.class, |
| 50 | + webhookHandler.onWebhook(eventName("conversation.new_message"), ConversationNewMessageEvent.class, |
51 | 51 | e -> Mono.fromRunnable(() -> log.info("Message received: {}", e.getConversationMessage().getFallbackText())), |
52 | | - canIgnoreOrder(), |
53 | | - ContextSpec.of( |
54 | | - "conversationId", it -> it.getConversationMessage().getConversationId() |
55 | | - )); |
| 52 | + WebhookHandlerOptions.contextSpec( |
| 53 | + ContextSpec.of( |
| 54 | + "conversationId", it -> it.getConversationMessage().getConversationId() |
| 55 | + ))); |
56 | 56 | } |
57 | 57 |
|
58 | 58 | private void echoIfSentByVisitor(BotDialogMessageRequest r) { |
|
0 commit comments