How to fix error "NOT_LOGGED_IN" in Voximplant? - voximplant

I'm trying to call with Voximplant and get this error. What's wrong?
CallManager: _handleAppStateChange: Current app state changed to inactive
CallManager.js:151 CallManager: _handleAppStateChange: Current app state changed to background
Client.js:563 Client: emit: no handlers for event: ConnectionClosed
CallManager.js:151 CallManager: _handleAppStateChange: Current app state changed to active
how can I make connection again in this situation ?
because of this user are not vaild to call another user. I have to close app and open again to make connection again
backend.js:12688 Possible Unhandled Promise Rejection (id: 0):
"NOT_LOGGED_IN"

You can check the client state before you call Client.call method. If the client state is not logged in, you need to connect and log in again, you can use login with access token to log in "silently", i.e. do not ask user to enter the password

Related

React query cancel / abort mutation if paused / offline

I'm using some mutations in a React Native app. I'd like to set a default behavior for all mutations so when I'm in offline mode and I try to make a mutation, display an error and do nothing. Right now, I've been able to catch this by using
mutationCache: new MutationCache({
onMutate: async (_, mutation) => {
if (mutation.state.isPaused) {
toastError("Network error!", "Please check your network connection");
mutation.state.status = "error";
}
}
})
where I set up my QueryClient(), but, when I switch to online mode again, the mutation gets fired. I'd like to avoid this situation, and just abort / discard / cancel the mutation instead of automatically resume it.
I've also tried calling mutation.destroy() but nothing happens.
How can I do it? Note I've tried to "force" the mutation status to "error" but I've still getting the same behavior.
I think there is nothing currently in react-query that would support this. The idea is that if a mutation has been fired, but it cannot be done because you're offline, the execution will be "deferred" until you are online again.
What you can do is:
not allow firing the mutation when you are offline. So basically, disable the button or whatever triggers the mutation.
set networkMode: 'always' (available in v4). This will fire mutations regardless of online / offline status. If you are offline, the mutation will fail with a network error. Then, you can display an error message. I think this is what you want given the requirements of "when I'm in offline mode and I try to make a mutation, display an error and do nothing."

How can I react to a message with a pub/sub bot

I have created a Card with a button and a onClick action that successfully sends a message to my client with type "CARD_CLICKED".
When I try to respond to this message with either a type "NEW_MESSAGE" or "UPDATE_MESSAGE" message, this is displayed as a new message, while the API tries for three times to send that CARD_CLICKED event to my bot until it gives up with the visual error: "Unable to contact [bot]. Try again later."
I guess this is similar to
Interactive button doesn't work properly when using pub/sub
Interactive cards hangout chat Api
but I am using a golang client and the answer to these questions didn't help me...
My code to respond to the "CARD_CLICKED" message:
func handleClick(message *chat.DeprecatedEvent) *chat.Message {
log.Debugf("User %s instructed me to execute %s", message.User.DisplayName, message.Action.ActionMethodName)
response := &chat.Message{
ActionResponse: &chat.ActionResponse{Type: "UPDATE_MESSAGE"},
Thread: &chat.Thread{Name: message.Message.Thread.Name},
Space: &chat.Space{Name: message.Message.Space.Name, Type: message.Message.Space.Type},
Text: "CARD CLICKED!",
}
return response
}
My code is based on this project: https://github.com/jforman/hangbot
Found out what the main issue was... I was calling the .Create() function - which created a new message and thus - even though the Action Response was set correctly - this was not interpreted as a response to the click event:
https://github.com/jforman/hangbot/blob/master/hangbot.go#L79
After I switched to calling .Update() - Chat would not display the "Unable to contact" message about my bot any more.
What remains is that the click event is still sent to me three times, but I'm filtering events now based on the eventTime, which works ok for now.

Detecting user canceling SKReceiptRefreshRequest to sign in

When we need to refresh an iOS7 receipt, the appropriate way to do that is to use SKReceiptRefreshRequest. This brings up an Apple dialog for the user to sign in using their Apple ID. It also allows them to Cancel. How can we detect if the user presses Cancel? (Of course, in iOS6, this can be done using catching the cancel event for [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]).
The SKReceiptRefreshRequest object has a delegate with two methods:
- (void)requestDidFinish:(SKRequest *)request;
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error;
In my code the requestDidFinish delegate method is called if the user does or does not press cancel.
The reason this is important to me is that I want to cancel the restore process if the user presses Cancel. If there was simply no receipt present after the refresh request, this might be relatively easy. However, sometimes there is a receipt (with some purchases) present in the app before the SKReceiptRefreshRequest, and so it stays in the app if the user cancels from the sign-in dialog.
I have two ideas for how to do this:
1) Delete the receipt from the bundle prior to the refresh request. The apparent problem with this is that the app can't remove files from the bundle (e.g., see Delete file from bundle after install). I tried. Nope.
2) Check the bytes of the receipt before the refresh request and after; if they differ, then this should indicate the user didn't press Cancel. If they don't differ, I'm not sure that does indicate they pressed Cancel. If the receipt contains purchases, I think that the bytes will differ because a refreshed receipt should have different transaction id's (but the same "original" transaction id's). If the receipt contains no purchases, I'm not sure about that.
Update, 11/9/15; I've just noticed that the delegate response to the user pressing Cancel appears to have changed. Now, didFailWithError is called. The problem of detecting user cancellation remains, however. How can we distinguish between the user pressing Cancel and a genuine error? I've been testing on iOS8.4 and iOS9.2 (beta). I have now reported this lack of distinguishability as a bug to Apple (bug #23476210).
Update, 11/10/15; This issue does not appear with iOS 9.0.2! I just tried this now with all three systems, with the same app binary, in the same approximate interval of time (within 20 minutes for all three systems): (A) iOS9.2 (13C5050d): Issue does occur (didFailWithError is called and can't distinguish between a real error and user pressing cancel), (B) iOS9.0.2, issue does not occur (requestDidFinish is called), and (C) iOS8.4.1, issue does occur. With all three system versions, this is running on real hardware, not the simulator.
iOS 9.2.1, Xcode 7.2.1, ARC enabled
I understand you asked this 2 years ago, but I recently had my run in with this issue and found a solution, and wanted to share here so others can save some time.
1) You may elect to store the receipt into keychain and access a copy of it, this allows you to delete it or refresh it as you see fit.
2) Yeah you can definitely check if it changed, I think the simplest way to do that is to use:
[receipt isEqualToData:(NSData *)(copyReceiptObject)]
My suggestion is as follows:
The key is to expect the error you get from the method:
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error;
that gets called when the user taps cancel after the log in dialogue comes up to sign in to iTunes Store. There are many custom was you could do the refresh request, so the results may vary, but here is the different error you get for my request:
When there is no connection to iTunes:
Error Domain=SSErrorDomain Code=110 "Cannot connect to iTunes Store"
UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store,
NSUnderlyingError=0x13c76d680 {Error Domain=NSURLErrorDomain
Code=-1009 "Cannot connect to iTunes Store"
UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store,
NSErrorFailingURLStringKey=
{ your product ids and corresponding URIs here }
, _kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12,
NSLocalizedDescription=The Internet connection appears to be offline.}}}
When the user taps cancel:
Error Domain=SSErrorDomain Code=16 "Cannot connect to iTunes Store"
UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store,
NSUnderlyingError=0x13c6ac7b0 {Error Domain=AKAuthenticationError
Code=-7003 "(null)"}}
The easiest I think is to check the error.code, if you want to get more complicated you may choose to parse the full error string to get more details about the error.
In my case, no connection error code is 110 and when the user cancels the log in the error code is 16. Handle the error.

How can I determine if a user cancels a CredentialsPicker?

How can I determine if a user cancels a CredentialsPicker?
You can try this in the Credential Picker sample. Using scenario 1, for example, you'll see that cancelation of the picker will return a CredentialPickerResults object (in the promise results or from the API in C#), in which the ErrorCode property (errorCode in JS) will contain x800704c7 which is the Win32 error code ERROR_CANCELLED.
If for some reason the credential picker cannot be displayed, that would generate an error from the credential picker itself (and be picked up by an error handler give to a promise.then). The case you're describing is that the credential picker succeeded, but the user canceled.

Requesting additional permission on new sdk, but dialog shows login form

In previous android SDK, I asked new permission by calling Facebook.authorize() and it showed approving permission screen. But in SDK 3.0, when I call FacebookActivity.openSessionForPublish() , dialog always shows login form. How can I show approving permission screen?
I've set up session that has token and expiration date and its SessionState is CREATED_TOKEN_LOADED .
Is there any requirement for showing permission dialog or does Facebook.authorize() always show login form? Then please teach me right method for that.
My code is like below
public class FbConn extends FacebookActivity {
public void onCreate(Bundle savedInstanceState) {
...
if( savedInstanceState == null ) {
Session savedSession = CommonUtil.getFbSession(CustomSessionStore.getFbInfo(getApplicationContext())); //get access token and expiration date from session store and set up new session.
Session.setActiveSession(savedSession);
setSession(savedSession);
}
}
protected void onStart() {
super.onStart();
openSessionForPublish(EpisodeApplication.config.getSelectedServer().fbAppId, Constants.FB_PERMISSIONS);
}
}
Update
I've commented out these lines and permission request screen showed successfully. But I don't sure this is right way or not.
In com.facebook.LoginActivity line 62,
Utility.clearFacebookCookies(this);
In com.facebook.Session line 1202,
Utility.clearFacebookCookies(getStaticContext());
If you already have a valid session, from a previous auth flow, then if you want to request new permissions then use the Session.ReauthorizeRequest class.
Session.ReauthorizeRequest reauthRequest = new Session
.ReauthorizeRequest(this, Constants.FB_PERMISSIONS);
session.reauthorizeForPublish(reauthRequest);
This should show a permissions screen for the new permissions you're asking for instead of the login form.
However, from looking at your logic it is not clear where you're handling the first time login. If you expect to handle it in this class then I suggest using the following:
Session.openActiveSession(this, true);
This will open up a login form if there is no cached token. If there is a cached token, it will create a new Session and make it active. This will open a session with basic permissions (if the user needs to log in) or open a session with the permissions based on the cached token retrieved. You can then call the re-auth methods to ask for publish permissions. You'll want to do that in context and typically do not want to call call the auth functions back to back, i.e. log the user in, then immediately ask for publish permissions.