-
Notifications
You must be signed in to change notification settings - Fork 18
2. Available APIs
void Crisp.configure(Context applicationContext, String websiteID)
void Crisp.configure(Context applicationContext, String websiteID, boolean resetToken)
void Crisp.configure(Context applicationContext, String websiteID, @Nullable String tokenID)Configures Crisp SDK with your websiteID and optionally (re)sets your user's tokenID.
It must be called at least once before starting ChatActivity!
Calling Crisp.configure(Context, String) will configure Crisp with your websiteID without (re)setting your user's tokenID.
It is useful when you do not need to set a tokenID for you user or just want to switch between your websites.
However, calling either Crisp.configure(Context, String, boolean) or Crisp.configure(Context, String, String) will (re)set it and will be used (or not if null or reset) unless a session already exists for the website. In this case, you will have to call Crisp.resetChatSession(Context context) before!
If the socket is already connected (so the ChatActivity is already started) when called, it will simply be ignored.
If websiteID is different from the previous one, any session, user, or action methods which have been called until then will be ignored, so call them after.
void Crisp.setTokenID(Context applicationContext, @Nullable String tokenID)(Un)sets the tokenID to be sent along the session creation.
It will be associated with the latest websiteID passed in Crisp.configure(Context, String).
Important
It must be called after calling Crisp.configure(Context, String) and before starting the ChatActivity!
If it is called after starting the ChatActivity, the session will be created without the tokenID so you will need to call Crisp.resetChatSession(Context context) and start over!
If you do not respect these conditions, it will simply be ignored
void Crisp.resetChatSession(Context applicationContext)Resets the current session bound to the current websiteID and its associated data in cache. Also clears pending session, user and action commands if any.
Important
Keep in mind that if you have set a tokenID in order to create this session, it will not be reset until you call Crisp.setTokenID(Context, String), so starting the ChatActivity will restore the session.
If the socket is already connected (so the ChatActivity is already started) when called, it is closed right away.
String Crisp.getSessionIdentifier(Context applicationContext)Returns the current sessionID if any and loaded (so the ChatActivity is already started and session joined).
void Crisp.enableNotifications(Context applicationContext, boolean enabled)Enables or not notifications for the current websiteID, default to false to avoid asking user for notifications permission while your websiteID is not configured to send them.
It must be called after calling Crisp.configure(Context, String) and before starting the ChatActivity!
If the socket is already connected (so the ChatActivity is already started) when called, it will simply be ignored.
Those methods are performed right away if the socket is already connected (i.e. the chatbox is opened), otherwise they are cached and will be sent when the session is loaded (i.e. on the next chatbox opening) unless you resetted the session or switched of website since, i.e. called one of these methods:
-
Crisp.configure(Context, String)with a differentwebsiteIDthan the current, -
Crisp.resetChatSession(Context context).
void Crisp.setSessionBool(String key, boolean value)
void Crisp.setSessionInt(String key, int value)
void Crisp.setSessionString(String key, String value)Sets a session data to the one provided.
void Crisp.setSessionSegment(String segment)
void Crisp.setSessionSegment(String segment, boolean overwrite)
void Crisp.setSessionSegments(List<String> segments)
void Crisp.setSessionSegments(List<String> segments, boolean overwrite)Sets the session segments to the ones provided, overwriting or not (default behavior) the previous ones.
void Crisp.pushSessionEvent(SessionEvent event)
void Crisp.pushSessionEvents(List<SessionEvent> events)Sends the session events provided.
boolean Crisp.setUserAvatar(String avatar)Sets the user avatar to the one provided, if it is valid.
Returns true if valid, false otherwise.
boolean Crisp.setUserEmail(String email)
boolean Crisp.setUserEmail(String email, String signature)Sets the user e-mail to the one provided, if it is valid, optionally verified with the signature provided as part of Identity verification.
Returns true if valid, false otherwise.
boolean Crisp.setUserPhone(String phone)Sets the user phone to the one provided, if it is valid.
Returns true if valid, false otherwise.
void Crisp.setUserCompany(Company company)Sets the user company to the one provided.
void Crisp.setUserNickname(String nickname)Sets the user nickname to the one provided.
void Crisp.runBotScenario(String scenarioId)Runs a bot scenario with the given scenarioId (from configured Bot scenarios, if the Bot plugin is enabled on your website).
Those methods are performed right away if the ChatActivity is currently running, on the next start otherwise unless you called one of these methods:
-
Crisp.configure(Context, String)with a differentwebsiteIDthan the current, -
Crisp.resetChatSession(Context context), - any other action method, except
Crisp.showMessage(Content)which is independent.
void Crisp.searchHelpdesk(Context applicationContext)Opens the Helpdesk tab if your Helpdesk is configured and the website chatbox is configured to display the Helpdesk tab.
void Crisp.openHelpdeskArticle(Context applicationContext, String id, String locale)
void Crisp.openHelpdeskArticle(Context applicationContext, String id, String locale, String title)
void Crisp.openHelpdeskArticle(Context applicationContext, String id, String locale, String title, String category)Opens the target Helpdesk article if your Helpdesk is configured and the website chatbox is configured to display the Helpdesk tab.
void Crisp.showMessage(Content content)Shows a message as operator in local chatbox.
You can create and send AnimationContent, AudioContent, CarouselContent, FieldContent, FileContent, PickerContent or TextContent.
Each of these classes can be instantiated either from:
- a
constructor(if messagetyperequires all its fields to be set, i.e.AnimationContent,AudioContent,FileContentorTextContent), - a
Builderclass (if messagetypehas optional fields, i.e.CarouselContent,FieldContent,PickerContent).
Crisp.showMessage(new TextContent("Hello world"));
Crisp.showMessage(new FieldContent .Builder("Id", "Text", "Placeholder")
.setRequired(true)
.build());You can register a callback for the following events:
-
session:loaded, -
chat:opened, -
chat:closed, -
message:sent, -
message:received.
void Crisp.addCallback(EventsCallback callback)Caution
Don't forget to unregister it as soon as you don't need it anymore as Crisp SDK keeps a strong reference on it!
void Crisp.removeCallback(EventsCallback callback)You can implement your own loggers following the interface below and add them to Crisp with the Crisp.addLogger(Logger logger) method.
interface Logger {
void log(String tag, Throwable cause);
void log(Logger.Level level, String tag, String message);
}Crisp already has its own Logger which outputs log to Logcat.
Adding your own will automatically disable it.
You can also set the level you want Crisp to log with the Crisp.setLogLevel(Logger.Level logLevel) method, available values are: ASSERT, ERROR, WARN (default), INFO, DEBUG and VERBOSE.
String Crisp.getSDKVersion()Returns the version of the Crisp SDK