-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature (Conversation/InjectMessage): Support 'injectMessage' API
- Loading branch information
Showing
12 changed files
with
515 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...m/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectMessageRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.sinch.sdk.domains.conversation.models.v1.conversation.request; | ||
|
||
import com.sinch.sdk.domains.conversation.models.v1.messages.ConversationMessageBody; | ||
|
||
/** Message to be injected */ | ||
public interface InjectMessageRequest extends InjectMessageRequestBase { | ||
|
||
/** | ||
* Get message body | ||
* | ||
* @return Body message | ||
*/ | ||
ConversationMessageBody getBody(); | ||
|
||
/** | ||
* Getting builder | ||
* | ||
* @return New Builder instance | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
static Builder<?> builder() { | ||
return new InjectMessageRequestImpl.Builder(); | ||
} | ||
|
||
/** Dedicated Builder */ | ||
interface Builder<B extends Builder<B>> extends InjectMessageRequestBase.Builder<B> { | ||
|
||
/** | ||
* see getter | ||
* | ||
* @param body see getter | ||
* @return Current builder | ||
* @see #getBody() | ||
*/ | ||
B setBody(ConversationMessageBody body); | ||
|
||
/** | ||
* Create instance | ||
* | ||
* @return The instance build with current builder values | ||
*/ | ||
InjectMessageRequest build(); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...nch/sdk/domains/conversation/models/v1/conversation/request/InjectMessageRequestImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.sinch.sdk.domains.conversation.models.v1.conversation.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.sinch.sdk.core.models.OptionalValue; | ||
import com.sinch.sdk.domains.conversation.models.v1.ChannelIdentity; | ||
import com.sinch.sdk.domains.conversation.models.v1.ConversationDirection; | ||
import com.sinch.sdk.domains.conversation.models.v1.ProcessingMode; | ||
import com.sinch.sdk.domains.conversation.models.v1.conversation.request.InjectMessageRequestBaseImpl.Builder; | ||
import com.sinch.sdk.domains.conversation.models.v1.messages.AppMessage; | ||
import com.sinch.sdk.domains.conversation.models.v1.messages.ContactMessage; | ||
import com.sinch.sdk.domains.conversation.models.v1.messages.ConversationMessageBody; | ||
import java.time.Instant; | ||
|
||
public class InjectMessageRequestImpl extends InjectMessageRequestBaseImpl | ||
implements InjectMessageRequest { | ||
|
||
@JsonIgnore | ||
public ConversationMessageBody getBody() { | ||
return appMessage() | ||
.map(f -> (ConversationMessageBody) f) | ||
.orElseGet(() -> contactMessage().orElse(null)); | ||
} | ||
|
||
protected InjectMessageRequestImpl( | ||
OptionalValue<AppMessage<?>> appMessage, | ||
OptionalValue<ContactMessage<?>> contactMessage, | ||
OptionalValue<Instant> acceptTime, | ||
OptionalValue<ChannelIdentity> channelIdentity, | ||
OptionalValue<String> contactId, | ||
OptionalValue<ConversationDirection> direction, | ||
OptionalValue<String> conversationId, | ||
OptionalValue<Boolean> injected, | ||
OptionalValue<String> senderId, | ||
OptionalValue<ProcessingMode> processingMode, | ||
OptionalValue<String> metadata) { | ||
super( | ||
appMessage, | ||
contactMessage, | ||
acceptTime, | ||
channelIdentity, | ||
contactId, | ||
direction, | ||
conversationId, | ||
injected, | ||
senderId, | ||
processingMode, | ||
metadata); | ||
} | ||
|
||
static class Builder<B extends Builder<B>> extends InjectMessageRequestBaseImpl.Builder<B> | ||
implements InjectMessageRequest.Builder<B> { | ||
|
||
public B setBody(ConversationMessageBody body) { | ||
if (body instanceof AppMessage) { | ||
this.appMessage = OptionalValue.of((AppMessage<?>) body); | ||
// TODO: CACORE-2213 workaround | ||
this.contactMessage = OptionalValue.of(null); | ||
} else if (body instanceof ContactMessage) { | ||
// TODO: CACORE-2213 workaround | ||
this.appMessage = OptionalValue.of(null); | ||
this.contactMessage = OptionalValue.of((ContactMessage<?>) body); | ||
} else { | ||
throw new IllegalStateException("Unexpected value: " + body); | ||
} | ||
return self(); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
protected B self() { | ||
return (B) this; | ||
} | ||
|
||
public InjectMessageRequest build() { | ||
return new InjectMessageRequestImpl( | ||
appMessage, | ||
contactMessage, | ||
acceptTime, | ||
channelIdentity, | ||
contactId, | ||
direction, | ||
conversationId, | ||
injected, | ||
senderId, | ||
processingMode, | ||
metadata); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.