Skip to content

Feature/agents online #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions RNZendeskChat.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ declare module "react-native-zendesk-chat" {
* Configure the token to start receiving Push Notifications
*/
registerPushToken: (token: string) => void;


/**
* Check if there are available agents
*/
areAgentsOnline: () => Promise<Boolean>;
}

const RNZendeskChatModule: RNZendeskChatModuleImpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import zendesk.chat.PushNotificationsProvider;
import zendesk.chat.ChatEngine;
import zendesk.chat.VisitorInfo;
import zendesk.chat.AccountStatus;
import zendesk.messaging.MessagingActivity;
import zendesk.messaging.MessagingConfiguration;

Expand Down Expand Up @@ -377,4 +378,29 @@ public void update(ChatState chatState) {
}
});
}

@ReactMethod
public void areAgentsOnline(Promise promise) {
Copy link

@moorjaniNitesh95 moorjaniNitesh95 May 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No import for Promise, resulting in compliation error in android, Please fix it, you cant use Promise

This comment was marked as outdated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Maybe it’s not. I’ll take a look tomorrow. We had some build issues due to jitpack.io being offline yesterday.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes its not and after npm install 0.4.1-beta.8 is getting installed and causing build error, you need to fix this, in a new PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Active fixes for 0.4.1 can be found in #85 -- 0.4.1-beta.9 is published and now building in our CI. If further fixes are needed, I'll publish more betas until it seems ready.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beta.9 passed compilation, so I'm shipping 0.4.1! -- If you find bugs, please report them.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @fbartho !!

Chat.INSTANCE.providers().accountProvider().getAccount(new ZendeskCallback<Account>() {
@Override
public void onSuccess(Account account) {
AccountStatus status = account.getStatus();

switch (status) {
case AccountStatus.ONLINE:
promise.resolve(true);
break;

default:
promise.resolve(false);
break;
}
}

@Override
public void onError(ErrorResponse errorResponse) {
reject();
}
});
}
}
19 changes: 19 additions & 0 deletions ios/RNZendeskChatModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,23 @@ - (void) dismissChatUI {
});
}

RCT_EXPORT_METHOD(areAgentsOnline:
(RCTPromiseResolveBlock) resolve
rejecter: (RCTPromiseRejectBlock) reject) {

[ZDKChat.accountProvider getAccount:^(ZDKChatAccount *account, NSError *error) {
if (account) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no account, this promise never resolves.

I'm going to add a code-snippet to reject in that situation.

switch (account.accountStatus) {
case ZDKChatAccountStatusOnline:
resolve(@YES);
break;

default:
resolve(@NO);
break;
}
}
}];
}

@end