Skip to content

Commit

Permalink
Merge pull request #10 from sinch/convo-snippet-first-draft
Browse files Browse the repository at this point in the history
Adding Conversation Snippet first draft (Java)
  • Loading branch information
JPPortier authored Oct 9, 2024
2 parents 40044c0 + 4900a8e commit c24555e
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions snippets/conversation/send/Snippet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package conversation;

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.types.text.*;
import java.util.*;
import java.util.Collections;
import java.util.logging.Logger;

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";

String body = "This is a test Conversation message using the Sinch Java SDK.";
String smsSender = "SMS_SENDER";

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);
}
}

0 comments on commit c24555e

Please sign in to comment.