From 2397c5921791e0067b9fa5fb0d08a37206b1bfd0 Mon Sep 17 00:00:00 2001 From: Sam Williams Date: Tue, 8 Oct 2024 11:16:50 -0400 Subject: [PATCH 1/2] Adding Conversation Snippet first draft --- snippets/conversation/send/Snippet.java | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 snippets/conversation/send/Snippet.java diff --git a/snippets/conversation/send/Snippet.java b/snippets/conversation/send/Snippet.java new file mode 100644 index 0000000..938a324 --- /dev/null +++ b/snippets/conversation/send/Snippet.java @@ -0,0 +1,56 @@ +package conversation; + +import com.sinch.sdk.domains.conversation.api.v1.*; +import com.sinch.sdk.domains.conversation.models.v1.*; +import com.sinch.sdk.domains.conversation.models.v1.messages.request.*; +import com.sinch.sdk.domains.conversation.models.v1.messages.response.SendMessageResponse; +import com.sinch.sdk.domains.conversation.models.v1.messages.*; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.text.*; +import java.util.Collections; +import java.util.logging.Logger; +import java.util.*; + +public class Snippet { + + private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName()); + + static void execute(ConversationService conversationService) { + + MessagesService messagesService = conversationService.messages(); + + String appId = "YOUR_app_id"; + String from = "YOUR_sms_sender"; + String to = "RECIPIENT_number"; + ChannelRecipientIdentity recipient = + ChannelRecipientIdentity.builder() + .setChannel(ConversationChannel.SMS) + .setIdentity(to) + .build(); + Collection recipients = new HashSet(); + recipients.add(recipient); + String body = "This is a test Conversation message using the Sinch Java SDK."; + String smsSender = "SMS_SENDER"; + + LOGGER.info("Sending SMS Text using Conversation API"); + SendMessageResponse value = + messagesService.sendMessage( + SendMessageRequest.builder() + .setAppId(appId) + .setRecipient( + ChannelRecipientIdentities.builder() + .setRecipientIdentities(recipients) + .build()) + .setMessage( + AppMessage.builder() + .setBody( + TextMessage.builder() + .setText(body) + .build()) + .build()) + .setChannelProperties( + Collections.singletonMap(smsSender, from)) + .build()); + + LOGGER.info("Response: " + value); + } +} \ No newline at end of file From 4900a8e4bcd47d49a33e61004e0d7fb9d1bb500b Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 8 Oct 2024 19:05:28 +0200 Subject: [PATCH 2/2] fix (Conversation/Snippet): Send snippet compilation fix and refactor --- snippets/conversation/send/Snippet.java | 57 ++++++++++++------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/snippets/conversation/send/Snippet.java b/snippets/conversation/send/Snippet.java index 938a324..773b8f8 100644 --- a/snippets/conversation/send/Snippet.java +++ b/snippets/conversation/send/Snippet.java @@ -1,14 +1,15 @@ package conversation; -import com.sinch.sdk.domains.conversation.api.v1.*; +import com.sinch.sdk.domains.conversation.api.v1.ConversationService; +import com.sinch.sdk.domains.conversation.api.v1.MessagesService; import com.sinch.sdk.domains.conversation.models.v1.*; +import com.sinch.sdk.domains.conversation.models.v1.messages.*; import com.sinch.sdk.domains.conversation.models.v1.messages.request.*; import com.sinch.sdk.domains.conversation.models.v1.messages.response.SendMessageResponse; -import com.sinch.sdk.domains.conversation.models.v1.messages.*; import com.sinch.sdk.domains.conversation.models.v1.messages.types.text.*; +import java.util.*; import java.util.Collections; import java.util.logging.Logger; -import java.util.*; public class Snippet { @@ -21,36 +22,34 @@ static void execute(ConversationService conversationService) { String appId = "YOUR_app_id"; String from = "YOUR_sms_sender"; String to = "RECIPIENT_number"; - ChannelRecipientIdentity recipient = - ChannelRecipientIdentity.builder() - .setChannel(ConversationChannel.SMS) - .setIdentity(to) - .build(); - Collection recipients = new HashSet(); - recipients.add(recipient); + String body = "This is a test Conversation message using the Sinch Java SDK."; String smsSender = "SMS_SENDER"; - LOGGER.info("Sending SMS Text using Conversation API"); - SendMessageResponse value = - messagesService.sendMessage( - SendMessageRequest.builder() - .setAppId(appId) - .setRecipient( - ChannelRecipientIdentities.builder() - .setRecipientIdentities(recipients) - .build()) - .setMessage( - AppMessage.builder() - .setBody( - TextMessage.builder() - .setText(body) - .build()) - .build()) - .setChannelProperties( - Collections.singletonMap(smsSender, from)) + ChannelRecipientIdentities recipients = + ChannelRecipientIdentities.of( + ChannelRecipientIdentity.builder() + .setChannel(ConversationChannel.SMS) + .setIdentity(to) .build()); + AppMessage message = + AppMessage.builder() + .setBody(TextMessage.builder().setText(body).build()) + .build(); + + SendMessageRequest request = + SendMessageRequest.builder() + .setAppId(appId) + .setRecipient(recipients) + .setMessage(message) + .setChannelProperties(Collections.singletonMap(smsSender, from)) + .build(); + + LOGGER.info("Sending SMS Text using Conversation API"); + + SendMessageResponse value = messagesService.sendMessage(request); + LOGGER.info("Response: " + value); } -} \ No newline at end of file +}