Closed mazenkh7 closed 5 years ago
You have not passed a handler to the RegisterDevice request, so you don't really know whether request has succeded or returned an error.
First of all, you need to register your app at https://my.telegram.org, obtaining api_id and api_hash, choose app's operating system as Android and then upload FCM certificates for your app.
Between, in TDLib 1.4.0 DeviceTokenGoogleCloudMessaging
was renamed to DeviceTokenFirebaseCloudMessaging
and full push notification handling was implemented in TDLib. See https://core.telegram.org/tdlib/notification-api for more details.
Thanks a lot, I will update tdlib. But there still is a problem, I registered my app before in my.telegram.org There's no where to select the operating system as android also there's no where to upload said fcm certificates. And I can't delete my app nor create new one
@mazenkh7 You have already chosen right operating system. The only thing you need to do is to upload FCM API key in the "GCM API key" section.
Thanks a lot for your help,
now after I did all that, I receive a "pushReceiver ID" from the registerDevice
function, but that's all
no notifications are received (onMessageReceived
from the my FirebaseMessagingService
is never called) or is this normal behavior and I should find the notifications elsewhere?
I read this https://core.telegram.org/tdlib/notification-api but i didn't quite understand where the PUSH notifications are received.
thanks.
(Also if there is a minimum working example for notifications, like the java example that would be great as I learned a lot from it)
To use TDLib Notification API you need to receive push notification as usually, then convert notification payload to JSON similar to examples in https://core.telegram.org/tdlib/notification-api#handling-push-notifications and pass it to ProcessPushNotification
.
If you don't receive notifications through FirebaseMessagingService.onMessageReceived
you need to recheck that server has accepted your GCM API key
, that you use your API ID in the app and that you pass correct token to registerDevice
. If this doesn't help please write API ID, user_id and other details to @tdlib_bot.
Thanks its showing successfully now, you're helpful and patient! The bot is amazing too.
I have another question though, why do i receive pending messages / delayed notifications? and what should I do if I know that I have delayed notifications.
If the user is offline, notifications are delayed in order to give him a chance to read the messages from a different device before the notification is shown.
First of all, you need to register your app at https://my.telegram.org, obtaining api_id and api_hash, choose app's operating system as Android and then upload FCM certificates for your app.
@levlam I don't see this section in my.telegram.org anymore. Is it still possible to register FCM certs?
cc/ @kiasaki
Edit: We're developing on web.
Looks like the push-notification option appears when you select android, not web. Is there a way to change the platform or revoke the api key/hash?
@MattNguyen FCM certificates is possible to register only if you are developing for Android and have chosen Android as operating system for your application. There is no way to change chosen platform after application is created.
Hi. I have already registered the device on Firebase, Telegram, have all. I run. Receive correctly the receiver id. So, my question is: Whats next? Because in the documentation say that have to enter on updateActiveNotifications and is not doing that. What i have to do,once i have the receiver ID?
ReceiverId is needed to launch correct TDLib instance with the same receiverId received from registerDevice. If you have only one account, then you don't need to use receiverId at all.
Accounts? Do you refer to user telegram account? I don undestand to you very well. Even is that, Tdlib is entering on some status, the user have pending notifications and tdlib do nothing.
@ljmartinez1994 Send logs with verbosity level 4 to @tdlib_bot.
recheck that server has accepted your
GCM API key
@levlam Hi, how can i check that the server has accepted my GCM API key?
@bantonen If you didn't receive an error while uploading the certificate at my.telegram.org, then it was accepted,
@levlam but if I am using Android, as I understand it, I do not need a certificate, right?
@bantonen You need to upload a valid API key from console.cloud.google.com for your api ID at my.telegram.org. Otherwise, Telegram will not be able to send push notifications to your app.
@levlam You mean these api keys https://firebase.google.com/docs/projects/api-keys#create-api-keys ?
@bantonen On this page there is a link to https://console.cloud.google.com/apis/credentials.
@levlam I am loading this api key but no notifications are coming. Can you please tell me what the problem might be. My app id (492896)
@bantonen You also need to write your user_id to @tdlib_bot.
@levlam How can I know if the API key I set is correct? After setting it, I still don't receive notifications. I'm looking forward to your reply.
You will receive an error about invalid API keys for any request.
@levlam Where can I see the error messages? After setting the API key, I directly saved it and there was no error reported, but I'm developing an Android app.Can I add you on Telegram? I hope you can guide me through this. Thank you very much.
Ah, sorry. Currently, there is no way to troubleshoot missing or invalid FCM certificate, because errors happen much later than certificate is set. The app will receive no push notifications, and there is no way to find the reason.
@levlam Can you tell me where to obtain the correct API key? Currently, Google Firebase has been modified, and I don't know where to get the correct API key.
I don't know, where the certificate can be found now. Support for new FCM API will be added soon, but the old one still work and certificate for it should be available somewhere, unless Google intentionally removed possibility to access it to force switch to the new API.
@levlam I think you should launch support for the new API as soon as possible. I saw in Google's Firebase backend that the old API key will not be usable at all starting from June 20, 2024. So, please update it as soon as possible. Also, will you update support for the new API on https://my.telegram.org at that time?
Yes, there should be changes at https://my.telegram.org/.
I have found that "Starting from 5/20/2024, new projects will no longer be allowed to enable our legacy APIs.", so you need to wait for the support of the new API, which is expected soon.
@levlam How long will it take to support the new API? Thank you for your support.
It is supposed to be publicly available before June 20.
@king-ma1993 It should be already possible to upload FCM credentials at api.telegram.org to use new push notification API.
@levlam Hi, I see the change, but why does the credentials JSON file returned by Google(Service Account by Firebase Admin SDK) report as invalid when I try to upload it? Do I need to convert it to a different format? Or did I get the wrong file?
@ponecrazy The file should be accepted. Could you edit the JSON file, removing the private key from it, and send the edited file to https://t.me/tdlib_bot?
@ponecrazy Could you try again now?
@levlam Now push is working, previously it was not successful because I changed the appid without relogging in. Thank you for your support.
In Android, Java; Since FCM, should be same as GCM I did the following after i created a Client object:
FirebaseInstanceId.getInstance().getInstanceId() .addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (!task.isSuccessful()) {
return;
}
// Get new Instance ID token from Firebase
token = task.getResult().getToken();
if (getToken() != null && !getToken().isEmpty())
client.send(new TdApi.RegisterDevice(new TdApi.DeviceTokenGoogleCloudMessaging(getToken()), null), null);
}
});
the token is registered successfully but i get no notifications at all, the function (onMessageReceived) doesn't get called.
is there anything else i should do? (i actually don't know what 'otherUserIDs' is and how to use it)