Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Conversation Snippet first draft (Java) #10

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix (Conversation/Snippet): Send snippet compilation fix and refactor
  • Loading branch information
JPPortier committed Oct 8, 2024
commit 4900a8e4bcd47d49a33e61004e0d7fb9d1bb500b
57 changes: 28 additions & 29 deletions snippets/conversation/send/Snippet.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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<ChannelRecipientIdentity> recipients = new HashSet<ChannelRecipientIdentity>();
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<TextMessage> message =
AppMessage.<TextMessage>builder()
.setBody(TextMessage.builder().setText(body).build())
.build();

SendMessageRequest<TextMessage> request =
SendMessageRequest.<TextMessage>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);
}
}
}
Loading