Class Smooch
- java.lang.Object
-
- io.smooch.core.Smooch
-
public final class Smooch extends java.lang.Object
Smooch Entry Point
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addConversationUiDelegate(int key, ConversationDelegate conversationUiDelegate)
Add aConversationDelegate
used by the smooch-ui packagestatic void
createConversation(java.lang.String name, java.lang.String description, java.lang.String iconUrl, java.lang.String avatarUrl, java.util.List<Message> messages, java.util.Map<java.lang.String,java.lang.Object> metadata, SmoochCallback<java.lang.Void> callback)
Create a conversation for the current user.static void
destroy()
Terminate the Smooch facilities.static Config
getConfig()
Accessor method for the currently connected app configuration.static Conversation
getConversation()
Accessor method for the current conversation.static void
getConversationById(java.lang.String conversationId, SmoochCallback<Conversation> callback)
Get aConversation
by its ID.static ConversationDelegate
getConversationDelegate()
Gets the delegate set viasetConversationDelegate(ConversationDelegate)
.static java.util.Collection<ConversationDelegate>
getConversationDelegates()
Gets the collection ofConversationDelegate
that have been set on the SDK as aSortedMap
where the integrator defined delegate will appear before the delegate used to notify the Smooch UIstatic void
getConversationsList(SmoochCallback<java.util.List<Conversation>> callback)
Get the list of the 10 most recently activeConversation
s for the current user, sorted from most recently updated to last.static ConversationDelegate
getConversationUiDelegate(int key)
Gets a delegate set viaaddConversationUiDelegate(int key, ConversationDelegate)
using the key.static ConversationViewDelegate
getConversationViewDelegate()
Gets the delegate set viasetConversationViewDelegate(ConversationViewDelegate)
.static java.lang.String
getFirebaseCloudMessagingProjectId()
Accessor method to get the Firebase Cloud Messaging project id that was linked to the application via the Web portal.static InitializationStatus
getInitializationStatus()
Accessor method for the current Initialization status.static LoginResult
getLastLoginResult()
Accessor for last knownLoginResult
ornull
if the user is anonymous orinit(Application, Settings, SmoochCallback)
hasn't been calledstatic MessageModifierDelegate
getMessageModifierDelegate()
Gets the delegate set viasetMessageModifierDelegate(MessageModifierDelegate)
.static void
getMoreConversationsList(SmoochCallback<java.util.List<Conversation>> callback)
Get the list of the 10 more recently activeConversation
s for the current user, sorted from most recently updated to last.static Settings
getSettings()
Accessor method for the SDK settings.static SmoochConnectionStatus
getSmoochConnectionStatus()
Accessor method for the currentSmoochConnectionStatus
, or null ifinit(Application, Settings, SmoochCallback)
hasn't been called yet.static boolean
hasMoreConversations()
Accessor method for knowing if there are more conversations to be fetched or not.static void
init(android.app.Application application)
Initializes Smooch without settings.static void
init(android.app.Application application, Settings settings, SmoochCallback<InitializationStatus> callback)
Initialize the Smooch SDK with the provided settings.static void
loadConversation(java.lang.String conversationId, SmoochCallback<Conversation> callback)
Loads a conversation by its ID and sets it as the active conversation for the current session.static void
login(java.lang.String externalId, java.lang.String jwt, SmoochCallback<LoginResult> callback)
Logs in a new Smooch user.static void
logout(SmoochCallback<LogoutResult> callback)
Logs out the current user.static void
setConversationDelegate(ConversationDelegate conversationDelegate)
Sets theConversationDelegate
static void
setConversationInputDisplayed(boolean displayed)
Toggles whether the input bar is displayed on the conversation view.static void
setConversationViewDelegate(ConversationViewDelegate conversationViewDelegate)
Sets theConversationViewDelegate
static void
setFirebaseCloudMessagingToken(java.lang.String token)
Method used to register the Firebase Cloud Messaging token to Smoochstatic void
setFirebaseCloudMessagingToken(java.lang.String token, SmoochCallback<LoginResult> callback)
Method used to register the Firebase Cloud Messaging token to Smoochstatic void
setMessageModifierDelegate(MessageModifierDelegate messageModifierDelegate)
Sets theMessageModifierDelegate
static void
startConversation(SmoochCallback<java.lang.Void> callback)
Deprecated.static void
updateConversationById(java.lang.String conversationId, java.lang.String name, java.lang.String description, java.lang.String iconUrl, java.util.Map<java.lang.String,java.lang.Object> metadata, SmoochCallback<Conversation> callback)
-
-
-
Method Detail
-
init
public static void init(android.app.Application application)
Initializes Smooch without settings. Use this only if you intend to callinit(Application, Settings, SmoochCallback)
outside of anApplication
classThis may only be called from
Application.onCreate()
.- Parameters:
application
- TheApplication
-
init
public static void init(android.app.Application application, Settings settings, SmoochCallback<InitializationStatus> callback)
Initialize the Smooch SDK with the provided settings.This may only be called from
Application.onCreate()
, unlessinit(Application)
was called there.Use
Smooch.getSettings()
to retrieve and modify the given settings object.- Parameters:
application
- TheApplication
settings
- TheSettings
to usecallback
- An optionalSmoochCallback
instance to be notified of the result. CallSmoochCallback.Response.getData()
to check theInitializationStatus
- See Also:
Settings
,SmoochCallback
,SmoochCallback.Response
,InitializationStatus
-
login
public static void login(java.lang.String externalId, java.lang.String jwt, SmoochCallback<LoginResult> callback)
Logs in a new Smooch user.You can either use this method to transition from logged out state to logged in, refresh the token of the existing logged in user or to switch the currently logged in user to a different one. You may not call login while the conversation screen is shown unless it is being called for the user already logged in. Doing so will result in a no-op.
init(Application, Settings, SmoochCallback)
must have been called prior to calling login.- Parameters:
externalId
- The distinct id of the user to login. Must not be null.jwt
- jwt used to prove the origin of the login request. Must not be null.callback
- An optionalSmoochCallback
instance to be notified of the result. CallSmoochCallback.Response.getData()
to check theLoginResult
- See Also:
SmoochCallback
,SmoochCallback.Response
,LoginResult
-
logout
public static void logout(SmoochCallback<LogoutResult> callback)
Logs out the current user.Calling this method while in anonymous state has no effect. You may not call logout while the conversation screen is shown. Doing so will result in a no-op.
- Parameters:
callback
- An optionalSmoochCallback
instance to be notified of the result. CallSmoochCallback.Response.getData()
to check theLogoutResult
- See Also:
SmoochCallback
,SmoochCallback.Response
,LogoutResult
-
startConversation
@Deprecated public static void startConversation(SmoochCallback<java.lang.Void> callback)
Deprecated.
-
createConversation
public static void createConversation(java.lang.String name, java.lang.String description, java.lang.String iconUrl, java.lang.String avatarUrl, java.util.List<Message> messages, java.util.Map<java.lang.String,java.lang.Object> metadata, SmoochCallback<java.lang.Void> callback)
Create a conversation for the current user.Creates a user and conversation on the server, allowing the business to reach out proactively to the user via the public API.
Creating a conversation via this method will count as a monthly active user (MAU) whether messages are exchanged or not, which may incur cost based on your plan. It is strongly recommended to only call this method in the case where a message is likely to be sent.
A List containing one
Message
can be passed in as well to add messages when the conversation is created. Only messages of type text are supported. Any other message type will cause an error.This method is called automatically when starting a conversation via the
Conversation.sendMessage(Message)
orConversation.uploadImage(Message, SmoochCallback)
methods, or when a user sends a message via the conversation activity.- Parameters:
name
- A user-friendly name to label the conversation in the list (max length 100).description
- A string describing the purpose of the conversation (max length 100).messages
- AList
of textMessage
to be sent when the conversation is created. Only messages of type text are supported. Any other message type will cause an error. The List can only contain one message.iconUrl
- An iconUrl to display in the conversation list. It should be a valid icon URL.avatarUrl
- An avatarUrl to display as the avatarcallback
- An optionalSmoochCallback
instance to be notified of the result.metadata
- The conversation metadata (JSON Object)- See Also:
SmoochCallback
,SmoochCallback.Response
-
loadConversation
public static void loadConversation(java.lang.String conversationId, SmoochCallback<Conversation> callback)
Loads a conversation by its ID and sets it as the active conversation for the current session.When called, subscribes the current device for push notifications on the passed conversationId, and sets the SDK to send and receive messages for that conversation going forward. Does not unsubscribe for notification on previously loaded conversations.
The provided callback contain the conversation that was loaded if successful.
If the conversation is already set to the passed id, this call will just return the currently loaded conversation.
- Parameters:
conversationId
- The conversationId to set.callback
- An optionalSmoochCallback
instance to be notified of the result.- See Also:
SmoochCallback
,SmoochCallback.Response
-
updateConversationById
public static void updateConversationById(java.lang.String conversationId, java.lang.String name, java.lang.String description, java.lang.String iconUrl, java.util.Map<java.lang.String,java.lang.Object> metadata, SmoochCallback<Conversation> callback)
- Parameters:
conversationId
- the conversationIdname
- A user-friendly name to label the conversation (max length 100 characters)description
- A string describing the purpose of the conversation (max length 100 characters)iconUrl
- An iconUrl to display in the conversation listmetadata
- The conversation metadata (JSON Object)callback
- An optionalSmoochCallback
instance to be notified of the result.- See Also:
SmoochCallback
,SmoochCallback.Response
-
destroy
public static void destroy()
Terminate the Smooch facilities.Smooch is automatically terminated when the application exits. This method does not, usually, have to be called manually.
-
getSettings
public static Settings getSettings()
Accessor method for the SDK settings.Use this object to update settings at run time. Note: Some settings may only be configured at init time. See the
Settings
class reference for more information.- Returns:
- Settings object passed in
init(Application, Settings, SmoochCallback)
, or null if Smooch hasn't been initialized yet. - See Also:
Settings
-
getConversation
public static Conversation getConversation()
Accessor method for the current conversation.- Returns:
- Current conversation, or null if Smooch.init() hasn't been called yet.
- See Also:
Conversation
-
getConversationById
public static void getConversationById(java.lang.String conversationId, SmoochCallback<Conversation> callback)
Get aConversation
by its ID. This is an asynchronous call and requires aSmoochCallback
to retrieve the result.- Parameters:
conversationId
- the ID of the conversation to be retrievedcallback
- An instance ofSmoochCallback
to be notified of the result.- See Also:
Conversation
-
getConversationsList
public static void getConversationsList(SmoochCallback<java.util.List<Conversation>> callback)
Get the list of the 10 most recently activeConversation
s for the current user, sorted from most recently updated to last.Note that these conversations will only contain the most recent message for that conversation. Use
getConversationById(String, SmoochCallback)
to retrieve the full details of a conversation, orloadConversation(String, SmoochCallback)
to make it active.- Parameters:
callback
- An instance ofSmoochCallback
to be notified of the result.- See Also:
getConversationById(String, SmoochCallback)
,loadConversation(String, SmoochCallback)
,getConversation()
-
getMoreConversationsList
public static void getMoreConversationsList(SmoochCallback<java.util.List<Conversation>> callback)
Get the list of the 10 more recently activeConversation
s for the current user, sorted from most recently updated to last.Note that these conversations will only contain the most recent message for that conversation. Use
getConversationById(String, SmoochCallback)
to retrieve the full details of a conversation, orloadConversation(String, SmoochCallback)
to make it active.- Parameters:
callback
- An instance ofSmoochCallback
to be notified of the result.- See Also:
getConversationById(String, SmoochCallback)
,loadConversation(String, SmoochCallback)
,getConversation()
-
hasMoreConversations
public static boolean hasMoreConversations()
Accessor method for knowing if there are more conversations to be fetched or not.- Returns:
- true if there is more conversations to be fetched or false if not.
-
getConfig
public static Config getConfig()
Accessor method for the currently connected app configuration.- Returns:
- Current app configuration, or null if Smooch.init() hasn't been called yet.
- See Also:
Config
-
getInitializationStatus
public static InitializationStatus getInitializationStatus()
Accessor method for the current Initialization status.- Returns:
- Initialization status, or null if
init(Application, Settings, SmoochCallback)
hasn't been called yet. - See Also:
InitializationStatus
-
getSmoochConnectionStatus
public static SmoochConnectionStatus getSmoochConnectionStatus()
Accessor method for the currentSmoochConnectionStatus
, or null ifinit(Application, Settings, SmoochCallback)
hasn't been called yet.- See Also:
SmoochConnectionStatus
-
getLastLoginResult
public static LoginResult getLastLoginResult()
Accessor for last knownLoginResult
ornull
if the user is anonymous orinit(Application, Settings, SmoochCallback)
hasn't been called- See Also:
LoginResult
-
getFirebaseCloudMessagingProjectId
public static java.lang.String getFirebaseCloudMessagingProjectId()
Accessor method to get the Firebase Cloud Messaging project id that was linked to the application via the Web portal.- Returns:
- The Firebase Cloud Messaging project Id
-
setFirebaseCloudMessagingToken
public static void setFirebaseCloudMessagingToken(java.lang.String token)
Method used to register the Firebase Cloud Messaging token to Smooch- Parameters:
token
- The Firebase Cloud Messaging token
-
setFirebaseCloudMessagingToken
public static void setFirebaseCloudMessagingToken(java.lang.String token, SmoochCallback<LoginResult> callback)
Method used to register the Firebase Cloud Messaging token to Smooch- Parameters:
token
- The Firebase Cloud Messaging tokencallback
- The callback to be called when token is received by Smooch
-
setConversationDelegate
public static void setConversationDelegate(ConversationDelegate conversationDelegate)
Sets theConversationDelegate
This delegate will be notified before the delegate set using
addConversationUiDelegate(int, ConversationDelegate)
Any delegate functions with the form boolean return type will prevent notification of conversationUiDelegate
- Parameters:
conversationDelegate
- an instance ofConversationDelegate
-
setConversationInputDisplayed
public static void setConversationInputDisplayed(boolean displayed)
Toggles whether the input bar is displayed on the conversation view.
-
getConversationDelegate
public static ConversationDelegate getConversationDelegate()
Gets the delegate set viasetConversationDelegate(ConversationDelegate)
.- Returns:
- an instance of
ConversationDelegate
-
addConversationUiDelegate
public static void addConversationUiDelegate(int key, ConversationDelegate conversationUiDelegate)
Add aConversationDelegate
used by the smooch-ui packageThe primary use of this property is to notify the Smooch UI of changes in the Conversation
Note that this delegate will be notified after the delegate set using
setConversationDelegate(ConversationDelegate)
- Parameters:
key
- the key to use, must be >= 1conversationUiDelegate
- an instance ofConversationDelegate
-
getConversationUiDelegate
public static ConversationDelegate getConversationUiDelegate(int key)
Gets a delegate set viaaddConversationUiDelegate(int key, ConversationDelegate)
using the key.- Parameters:
key
- the key to use- Returns:
- an instance of
ConversationDelegate
, null if not delegate for key
-
getConversationDelegates
public static java.util.Collection<ConversationDelegate> getConversationDelegates()
Gets the collection ofConversationDelegate
that have been set on the SDK as aSortedMap
where the integrator defined delegate will appear before the delegate used to notify the Smooch UI- Returns:
- a
SortedMap
ofConversationDelegate
-
setConversationViewDelegate
public static void setConversationViewDelegate(ConversationViewDelegate conversationViewDelegate)
Sets theConversationViewDelegate
The delegate allows you to be notified of events related to the conversation view
- Parameters:
conversationViewDelegate
- an instance ofConversationViewDelegate
-
getConversationViewDelegate
public static ConversationViewDelegate getConversationViewDelegate()
Gets the delegate set viasetConversationViewDelegate(ConversationViewDelegate)
.- Returns:
- an instance of
ConversationViewDelegate
-
setMessageModifierDelegate
public static void setMessageModifierDelegate(MessageModifierDelegate messageModifierDelegate)
Sets theMessageModifierDelegate
The delegate allows you to change the way messages are displayed or sent to Smooch.
- Parameters:
messageModifierDelegate
- The messageModifierDelegate
-
getMessageModifierDelegate
public static MessageModifierDelegate getMessageModifierDelegate()
Gets the delegate set viasetMessageModifierDelegate(MessageModifierDelegate)
.- Returns:
- an instance of
MessageModifierDelegate
-
-