You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zh...@apache.org on 2022/04/20 01:58:47 UTC

[camel-quarkus] branch main updated: Telegram integration test : test sending message with customized keyboard (#3735)

This is an automated email from the ASF dual-hosted git repository.

zhfeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new d3ffaa0370 Telegram integration test : test sending message with customized keyboard (#3735)
d3ffaa0370 is described below

commit d3ffaa0370ed3645d0345cae1fd643db297b7715
Author: Zineb BENDHIBA <be...@gmail.com>
AuthorDate: Wed Apr 20 03:58:42 2022 +0200

    Telegram integration test : test sending message with customized keyboard (#3735)
---
 .../component/telegram/it/TelegramResource.java    | 31 ++++++++++++++++++++--
 .../resources/mappings/telegramSendMessage.json    |  2 +-
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramResource.java b/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramResource.java
index a6dc6fe1db..ad085f4ddd 100644
--- a/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramResource.java
+++ b/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramResource.java
@@ -17,6 +17,7 @@
 package org.apache.camel.quarkus.component.telegram.it;
 
 import java.net.URI;
+import java.util.Arrays;
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
@@ -34,6 +35,9 @@ import org.apache.camel.ProducerTemplate;
 import org.apache.camel.component.telegram.TelegramConstants;
 import org.apache.camel.component.telegram.TelegramMediaType;
 import org.apache.camel.component.telegram.model.EditMessageLiveLocationMessage;
+import org.apache.camel.component.telegram.model.InlineKeyboardButton;
+import org.apache.camel.component.telegram.model.OutgoingTextMessage;
+import org.apache.camel.component.telegram.model.ReplyKeyboardMarkup;
 import org.apache.camel.component.telegram.model.SendLocationMessage;
 import org.apache.camel.component.telegram.model.SendVenueMessage;
 import org.apache.camel.component.telegram.model.StopMessageLiveLocationMessage;
@@ -68,9 +72,32 @@ public class TelegramResource {
     @POST
     @Consumes(MediaType.TEXT_PLAIN)
     @Produces(MediaType.TEXT_PLAIN)
-    public Response postMessage(String message) throws Exception {
+    public Response postMessage(String msg) throws Exception {
+        OutgoingTextMessage message = new OutgoingTextMessage();
+        message.setText(msg);
+
+        // customize keyboard
+        InlineKeyboardButton buttonOptionOneI = InlineKeyboardButton.builder()
+                .text("Option One - I").build();
+
+        InlineKeyboardButton buttonOptionOneII = InlineKeyboardButton.builder()
+                .text("Option One - II").build();
+
+        InlineKeyboardButton buttonOptionTwoI = InlineKeyboardButton.builder()
+                .text("Option Two - I").build();
+
+        ReplyKeyboardMarkup replyMarkup = ReplyKeyboardMarkup.builder()
+                .keyboard()
+                .addRow(Arrays.asList(buttonOptionOneI, buttonOptionOneII))
+                .addRow(Arrays.asList(buttonOptionTwoI))
+                .close()
+                .oneTimeKeyboard(true)
+                .build();
+
+        message.setReplyMarkup(replyMarkup);
+
         producerTemplate.requestBody(String.format("telegram://bots?chatId=%s", chatId), message);
-        log.infof("Sent a message to telegram %s", message);
+        log.infof("Sent a message to telegram %s", msg);
         return Response
                 .created(new URI(String.format("https://telegram.org/")))
                 .build();
diff --git a/integration-tests/telegram/src/test/resources/mappings/telegramSendMessage.json b/integration-tests/telegram/src/test/resources/mappings/telegramSendMessage.json
index eb561fda0f..ef14cb37c6 100644
--- a/integration-tests/telegram/src/test/resources/mappings/telegramSendMessage.json
+++ b/integration-tests/telegram/src/test/resources/mappings/telegramSendMessage.json
@@ -5,7 +5,7 @@
     "url" : "/botfake-token/sendMessage",
     "method" : "POST",
     "bodyPatterns" : [ {
-      "equalToJson" : "{\"text\":\"A message from camel-quarkus-telegram\",\"chat_id\":\"1426416050\"}",
+      "equalToJson" : "{ \"text\": \"A message from camel-quarkus-telegram\", \"chat_id\": \"1426416050\", \"reply_markup\": { \"keyboard\": [  [ {  \"text\": \"Option One - I\" }, {\"text\": \"Option One - II\"}],[{\"text\": \"Option Two - I\"}]],\"one_time_keyboard\": true}}",
       "ignoreArrayOrder" : true,
       "ignoreExtraElements" : true
     } ]