Open reygie25 opened 2 months ago
Hi @reygie25 and thank you for your feedback.
On my side, I use the HTML integration for test purposes, not the npm package, but it should behave the same way as it's only a wrapper.
However, the following works well on my side, I recover the same session_id
on both Web and Android:
<script type="text/javascript">
$crisp=[];
CRISP_WEBSITE_ID=website_id;
CRISP_TOKEN_ID=user_id;
(function(){d=document;s=d.createElement("script");s.src="https://client.crisp.chat/l.js";s.async=1;d.getElementsByTagName("head")[0].appendChild(s);})();
</script>
Crisp.setWebsiteId(context, website_id);
Crisp.resetChatSession();
Crisp.setTokenID(context, user_id);
startActivity(new Intent(context, ChatActivity.class));
Be sure to call Crisp.resetChatSession()
before setting the TokenID
, it will do nothing if a session already exists!
See documentation.
Hello @Doc1faux! Thank you for your response.
Here's my complete code snippet for Android and yes I always call that Crisp.resetChatSession()
when opening the crisp view
private void initCrispChat(Context context, UserProfile profile) {
Crisp.resetChatSession(context);
if(profile == null){//anonymous user
Crisp.setTokenID(context, user.userID);
Crisp.setSessionString("user_id", user.userID);
Log.d("crisp_logger", "ANONYMOUS USER ID: " + user.userID);
}else {
Crisp.setTokenID(context, profile.getUserId());
Log.d("crisp_logger", "SessionId: " + Crisp.getSessionIdentifier(context) + " Token Id:" + profile.getUserId());
}
isCrispChatActive = true;
startActivity(new Intent(context, im.crisp.client.ChatActivity.class));
}
The issue we encountered is intermittent sometimes its working properly but there's a chance we encountered it randomly. Do you have any suggestion about it?
if you call Crisp.resetChatSession(context)
before calling Crisp.setTokenID(context, tokenID)
, it should work indeed.
When you call Crisp.setTokenID(context, tokenID)
, are you sure the chatbox is not opened? It is ignored in this case.
Do you use an unmodified Activity or Application Context
? One of our customers got an issue recently where he cannot join the chat, so it's worth checking.
Are you working with one or more websiteID
?
Keep in mind that Crisp.getSessionIdentifier(context)
returns the sessionId
only when the chatbox is opened and the session:joined
event received from socket, it returns null
otherwise.
When you call Crisp.setTokenID(context, tokenID), are you sure the chatbox is not opened? It is ignored in this case
Answer: Yes, as you can see in the code snippet the startActivity is at the bottom, so the chat box is not yet opened when calling the Crisp.setTokenID.
Do you use an unmodified Activity or Application?
Answer: What do you mean by unmodified activity or application? can you enlighten me about this or give us an example?
Are you working with one or more websiteID?
Answer: Yes, we're using a different websiteID for each account, and we only encountered this issue on a TRIAL account. Please check the image below.
Keep in mind that Crisp.getSessionIdentifier(context) returns the sessionId only when the chatbox is opened and the session:joined event received from socket, it returns null otherwise.
Thank you for this clarification, that's why it always returns a null value
Hi @reygie25, sorry for getting back to you late,
About the Activity
or Application
Context
, one of our customer said:
there was a function overriding the
Context
of theAppContext
into aLocale
configured version of theContext
. This made your chat not load correctly.
I'll check if I got the issue too with a trial website.
The scenario here is when the web sdk started a session.
Web SDK
To send or initiate a first-time message to a contact or workers (which we call), using the Web SDK, we open the chatbox to generate a session_id which is needed to send the message. Here's our example code:
ANDROID SDK