Skip to content

Instantly share code, notes, and snippets.

View AlexPrestonSB's full-sized avatar

Alex Preston AlexPrestonSB

View GitHub Profile
@AlexPrestonSB
AlexPrestonSB / README.md
Last active May 18, 2026 19:56
Fix: Guardant MAChat historical agent messages mislabeled as 'AI Assistant' in closed-ticket view

Fix: Historical agent messages mislabeled as "AI Assistant"

Issue: In the closed-ticket history view, messages from human agents were being mislabeled with the hardcoded string "AI Assistant". Root cause: the renderer used a UUID-shape heuristic on userSendbirdId to decide whether a message came from the AI bot. Sendbird Desk gives both AI bots and human agents UUID-style IDs (humans are prefixed with sendbird_desk_agent_id_), so any human agent matched the heuristic and got mislabeled. The label was also hardcoded — ignoring the bot's actual nickname in Sendbird.

Fix approach: Match how the Sendbird Desk dashboard renders names — just show the sender's nickname from the message payload, no special "AI" string. For the small blue AI badge next to bot messages, identify the bot via Sendbird Desk's userId prefix convention: human agents are prefixed with "sendbird_desk_agent_id_", the AI bot is not.

All changes are in src/components/MAChat.js, inside the closed-ticket message renderer

@AlexPrestonSB
AlexPrestonSB / build.gradle
Created August 27, 2020 17:04
Add the Sendbird SDK to the app level gradle file where your other dependencies reside.
dependencies {
implementation 'com.sendbird.sdk:sendbird-android-sdk:3.0.141'
...
}
@AlexPrestonSB
AlexPrestonSB / SenderReadReceipt.java
Last active August 7, 2020 21:44
Getting updates for read receipts.
//Sender Side
// To listen to an update from all the other channel members' client apps, implement the 'onReadReceiptUpdated()' with things to do when notified.
SendBird.addChannelHandler(UNIQUE_HANDLER_ID, new SendBird.ChannelHandler() {
@Override
public void onReadReceiptUpdated(GroupChannel groupChannel) {
if (currentGroupChannel.getUrl().equals(groupChannel.getUrl())) {
// For example, code for redrawing a channel view.
}
}
});
@AlexPrestonSB
AlexPrestonSB / ReceiverMarkAsRead.java
Last active August 7, 2020 21:43
Marking a message as read.
//Receiver Side
// Call the 'markAsRead()' when the current user views unread messages in a group channel.
groupChannel.markAsRead();
...
@AlexPrestonSB
AlexPrestonSB / ReceiverMarkAsRead.java
Created August 7, 2020 21:36
Marking a message as read
//Receiver Side
// Call the 'markAsRead()' when the current user views unread messages in a group channel.
groupChannel.markAsRead();
...
@AlexPrestonSB
AlexPrestonSB / SenderDeliveryReceipt.java
Last active August 7, 2020 21:43
Sender side for getting an update for messages that are marked as delivered.
//Sender’s side
SendBird.addChannelHandler(UNIQUE_HANDLER_ID, new SendBird.ChannelHandler() {
@Override
public void onMessageReceived(BaseChannel baseChannel, BaseMessage baseMessage) {
}
@Override
public void onDeliveryReceiptUpdated(GroupChannel channel) {
...
@AlexPrestonSB
AlexPrestonSB / ReceiverMarkAsDelivered.java
Last active August 7, 2020 21:42
Receiver side for marking messages as delivered.
//Receiver Side
public class FirebaseMessagingServiceEx extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
try {
JSONObject sendBird = new JSONObject(remoteMessage.getData().get("sendbird"));
JSONObject channel = (JSONObject) sendBird.get("channel");
String channelUrl = (String) channel.get("channel_url");
//Mark the Message as Delivered
@AlexPrestonSB
AlexPrestonSB / MessageResend.java
Last active August 7, 2020 21:41
Snippet showing how to set the retry policy for Sync Manager.
SendBirdSyncManager.Options options = new SendBirdSyncManager.Options.Builder()
.setMessageResendPolicy(SendBirdSyncManager.MessageResendPolicy.AUTOMATIC)
.setAutomaticMessageResendRetryCount(5)
.build();
SendBirdSyncManager.setup(context, userId, options, handler);
@AlexPrestonSB
AlexPrestonSB / SyncManager.java
Last active August 7, 2020 21:41
Getting messages from the server.
@Override
protected void onResume() {
super.onResume();
SendBird.addConnectionHandler(YOUR_CONNECTION_HANDLER_ID, new SendBird.ConnectionHandler() {
@Override
public void onReconnectStarted() {
SendBirdSyncManager.getInstance().pauseSync();
}
@AlexPrestonSB
AlexPrestonSB / FailedMessage.java
Created August 7, 2020 21:27
Event for when a message fails to send.
@Override
public void onFailedMessageEvent(MessageCollection collection, final List<BaseMessage> messages, final MessageEventAction action, final FailedMessageEventActionReason reason) {
if (getActivity() == null) {
return;
}
}