22
33import com .unblu .middleware .bots .annotation .UnbluBots ;
44import com .unblu .middleware .bots .service .DialogBotService ;
5+ import com .unblu .middleware .common .entity .ContextSpec ;
56import com .unblu .middleware .webhooks .annotation .UnbluWebhooks ;
67import com .unblu .middleware .webhooks .service .WebhookHandlerService ;
78import com .unblu .webapi .jersey .v4 .api .BotsApi ;
@@ -34,20 +35,24 @@ public class TestMiddlewareService implements ApplicationRunner {
3435 @ Override
3536 public void run (ApplicationArguments args ) {
3637 // accept every onboarding offer
37- dialogBotService .acceptOnboardingOfferIf (_o -> Mono .just (true ));
38+ dialogBotService .acceptOnboardingOfferIf (_o -> Mono .just (true )
39+ .doOnNext (_r -> log .info ("Accepting as usual" )));
3840
3941 // greet the user when a dialog is opened
4042 dialogBotService .onDialogOpen (r ->
41- Mono .fromRunnable (() -> sendMessage (r .getDialogToken (), "Hello, I am a bot!" )));
43+ Mono .fromRunnable (() -> sendMessage (r .getDialogToken (), "Hello, I am a bot!" )));
4244
4345 // echo every message back to the user
4446 dialogBotService .onDialogMessage (r ->
45- Mono .fromRunnable (() -> echoIfSentByVisitor (r )));
47+ Mono .fromRunnable (() -> echoIfSentByVisitor (r )));
4648
4749 // log every message sent anywhere using a webhook handler
4850 webhookHandlerService .onWebhook (eventName ("conversation.new_message" ), ConversationNewMessageEvent .class ,
4951 e -> Mono .fromRunnable (() -> log .info ("Message received: {}" , e .getConversationMessage ().getFallbackText ())),
50- canIgnoreOrder ());
52+ canIgnoreOrder (),
53+ ContextSpec .of (
54+ "conversationId" , it -> it .getConversationMessage ().getConversationId ()
55+ ));
5156 }
5257
5358 private void echoIfSentByVisitor (BotDialogMessageRequest r ) {
@@ -58,6 +63,7 @@ private void echoIfSentByVisitor(BotDialogMessageRequest r) {
5863
5964 private void sendMessage (String dialogToken , String text ) {
6065 try {
66+ log .info ("Sending message: {}" , text );
6167 botsApi .botsSendDialogMessage (new BotDialogPostMessage ()
6268 .dialogToken (dialogToken )
6369 .messageData (new TextPostMessageData ().text (text )));
0 commit comments