Trigger.io doesn't expose the user's agreement to notifications in iOS - notifications

I am building a trigger.io app (ios+Android) with notifications through parse.com.
Notifications are working, but I am unable to test for whether the user has agreed to notifications before trying to subscribe to a channel with forge.parse.push.subscribe. This is generally only a problem on first run of the app.
forge.parse.installationInfo will return an info.id, even if that user hasn't agreed to notifications, so it can't be used to test for agreement:
forge.parse.push.subscribe throws an error if the user hasn't agreed to notifications:
{ "message":"Subscribing to Parse channel failed: Error Domain=Parse Code=115
\\"The operation couldn’t be completed. (Parse error 115.)
\\" UserInfo=0x165ddbc0 {code=115,
error=There is no device token stored yet.}","type":"UNEXPECTED_FAILURE"}'
I could set a timeout to try subscribing again later in case the user has since accepted notifications, but I'm not happy with having to send multiple REST requests to parse.com to see if the user has agreed to notifications.
forge.parse.registerForNotifications just delays the registration process, but doesn't throw an error if the user doesn't agree to notifications.
Trigger.io displays a console event when the user accepts:
Initializing Parse and subscribing to default channel.
Can this also expose an event to forge to be accessed in the js when the user agrees to notifications?
Or should forge.parse.installationInfo throw an error if the user doesn't have notifications on?

Related

Getting Unauthorized on Create ChatMessage even though Application has Teamwork.Migrate.All permission (BETA)

I'm using the /beta endpoints for Microsoft Graph API, but I'm getting an Unauthorized error when trying to create chat messages on behalf of other users (or any user).
In v1.0 of the API, the Create chatMessage method is not Supported, but in Beta it is: https://learn.microsoft.com/en-us/graph/api/channel-post-message?view=graph-rest-beta&tabs=http, as "Teamwork.Migrate.All" permission, which my Application has in Azure.
It is strange, because the same App can create Teams, channels and add members, but not add channel messages.
Anyone know where to look next?
Edit: I got this back now: "You need to add user delegated permissions in your application to at least Group.ReadWrite.All in portal.azure.com and then consent as user or Grant admin consent in portal. And re-run On behalf of a User | Get User Access Token request to update access token."
However, it does not make sense in regards to what the Beta documentation says about the permission "Teamwork.Migrate.All", which my app has as an "Application Permission": "Allows the app to create chat and channel messages, without a signed in user. The app specifies which user appears as the sender, and can backdate the message to appear as if it was sent long ago. The messages can be sent to any chat or channel in the organization."
If I'm an app and I have that permission, what should I do with a User Access Token? I'm using the App Access Token.
For simply posting message to Teams Channel using Application Permission is not supported by Microsoft Graph
Alternatively you can setup Incoming Webhook which is connector in MsTeams's channel and after finish set up on Teams channel you will received URL which you could use Postman or any API consumer app to send request(your message) to Incoming Webhook which will be post in Teams Channel
Sample Result Image
NOTE: Incoming Webhook is not support for replying post
You need to add user delegated permissions in your application to at
least Group.ReadWrite.All in portal.azure.com and then consent as user
or Grant admin consent in portal. And re-run On behalf of a User | Get
User Access Token request to update access token.
It seems that you need to use a user token instead of an application token to create chat messages. The only difference between them is that the user token requires the user to log in. The application token allows the application to create chat messages on behalf of other users. Currently, you can only use user tokens.
As your prompt message says, you need to grant the Group.ReadWrite.All delegation permission to the application, and then grant the admin consent for the permission, and then you need to use the auth code flow to obtain the access token.
Update:
I think what you are doing is importing messages, not creating chat messages, it does require you to have the Teamwork.Migrate.All application permission.
Importing messages is special, it requires you to create team and create achannel in the migration state, you need to include the migration value in the teamCreationMode and channelCreationMode instance attributes in the POST request. See: here.

stop gcm to send notification on old registration id

Suppose that case when the client app has re-registered with the gcm itself but the server is unaware of this and now the server is sending notification to that particular client what I want is the notification should not be sent with the old registration id. How can this be done?
If your server sends a message to an invalid Registration token, it will probably receive a NotRegistered error response. You should handle this error accordingly by removing the corresponding token. As per the documentaion I linked above:
For all these cases, remove this registration token from the app server and stop using it to send messages.

Any way to get more details on GCM failure?

I'm currently working on a push notification API that will work with several apps at once, handling notifications and reducing programming time for future apps. It's already partially working, as I'm able to register and receive notifications on Android devices.
Eventually, one of our apps is gonna send broadcast notifications to registered users. But some tokens might be expired, which will lead to a GCM failure. I already tested, and it seems that sending an array of tokens to GCM with a single http call is working really well, as devices with valid tokens got their notifications.
What I wasn't able to find searching GCM documentation was a way to get more details in case of failure. For example, when I send a notification to two users, one with a valid token and the other with an invalid one, I got this result :
{
"multicast_id":7625209716676388798,
"success":1,
"failure":1,
"canonical_ids":0,
"results":[
{"error":"InvalidRegistration"},
{"message_id":"0:1466511379030431%c4718df8f9fd7ecd"}
]
}
We can see that one of the messages failed to send, but what I'm looking for is a way to get more details, ideally the token that leads to a failure, so I can remove it from my database.
Any way to achieve that ? Using the message_id maybe ? Or is there any solution for me to find invalid tokens stored in my database so I can clear them ? I might have missed something in the documentation, even a link to it would be useful.
Based from this documentation, the GCM server will respond to your server with some information about the token you used to try to send the push notification.
According also to this link, if the app server fails to complete its part of the registration handshake, the client app should retry sending registration token to the server or delete the registration token. Wiping old tokens from the GCM servers can be done with ÌnstanceID.deleteToken().
Check these links:
How to remove gcm id from server which is not used
GCM get invalid tokens when sending to multiple devices at once

Q: Getting "socket closed by remote peer" when trying to login/sign in to Quickblox server

fellow stackoverflowians,
I'm working on a personal project to develop an iOS based chat app that uses Quickblox for its chat functionality.
Just recently we started getting the following error when trying to establish a connection to the Quickblox server and register or sign in a user.
TestApp[3975:76577] -[QBChat loginWithUser:] -> Connecting to Chat, hostName:chat.quickblox.com
TestApp[3975:76577] -[QBChat loginWithUser:] -> Chat server endpoint: chat.quickblox.com, User
Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer}
Sometimes our app is able to log in.. and sometimes it just completely fails all of the time. We cannot figure out if it's the Quickblox server that's having issues or if there's a fix in our code that needs to be added.
Can someone out there please shed some light? We are about to release our app and this is a MAJOR hurdle preventing us from doing so. We cannot get anyone from Quickblox to respond to our ticket. We are an Advanced user (not Pro) and therefore our ticket hasn't been looked at.
Please see the below given code which we use for Quickblox registration and Quickblox sign in. See my inline comments also.
[self CallQBRegister:^{
// I am checking whether the user is already registered or not.
NSLog(#"Successfully registered..");
}
// If already registered then the execution block will come to error block.
// there I am attempting to use Quickblox sign in process.
errorBlock:^{
NSLog(#"Already Registered, Active State is not Changed. Call QB Sign in");
[self callQBSignIn:^{
NSLog(#"QB Login success");
}
errorBlock:^{
NSLog(#"QB Login Failure");
}];
}];
}
After that I am also checking if connection fails I am trying to reconnect with QBChat.
- (void)chatDidFailWithError:(NSInteger)code{
// re login here
[[QBChat instance] loginWithUser:self.currentUser];
}
When ever I am getting this error this code snippet will execute. The code which I am getting here it belongs to an error type, which I have defined in my code. The error what I am getting is "QBChatServiceErrorConnectionRefused".
can anyone help?
Quickblox.. are you listening?

Server got InternalServerError, but device receive the notification

I implemented a GCM server to send notification, as well as a GCM Android client to receive notification.
Most of the time, they were working good. But some times the server got InternalServerError response, like that:
{"multicast_id":7727132596694632507,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InternalServerError"}]}
When got this reponse,
1. some times the device can not receive notification.
2. but some times the device can receive notification(event InternalServerError responsed).
I know should retry send when got InternalServerError. But that may cause duplicated notification sending for the situation 2.
How to resolve that?