Skip to content

Conversation

@ikusa
Copy link

@ikusa ikusa commented May 29, 2023

Background

This pull request aims to address the issue of handling receipts with error status. Currently, the expo-server-sdk-ruby implementation on the original_push_token relies on field message exposed by the Expo API response to access the push token associated with a receipt.

Problem

An issue has been identified (see GitHub issue #7795) where the Expo API response no longer includes the push token for the respective receipt. Consequently, there is currently no way to retrieve the push token from a receipt.

Proposed Solution

To overcome this problem, we propose the following solution: since the Expo API returns the receipt results in the same order as the push notifications are sent, we can determine the token associated with each receipt ID.

Changes

  1. Added the all_recipients method to the Chunk class, which retrieves all the tokens to which push notifications are being sent.
  2. Added the token parameter to the constructor of the Ticket class.
  3. Replaced the original_push_token method with the new token supplied in the constructor.
  4. Added the token_by_receipt_id method, which returns a hash mapping tokens to their respective receipt IDs.

Example Usage

Here is a small code snippet demonstrating the usage of the newly added functions:

token_by_receipt_id = tickets.token_by_receipt_id
batches = tickets.batch_ids
batches.each do |current_batch_receipt_ids|
  push_notification_receipt_ids = []
  current_batch_receipt_ids.each do |receipt_id|
    expo_pn_token = token_by_receipt_id[receipt_id]
    # Rest of the code...
  end
end

These changes will enable the retrieval of push tokens associated with receipts, allowing for proper handling of receipts with error status.

@SleeplessByte
Copy link
Owner

Are you really not seeing the push tokens in the errors anymore? Because I think we do.

@ikusa
Copy link
Author

ikusa commented Jun 7, 2023

We do get push token on /api/v2/push/send

But /api/v2/push/getReceipts would result with this response

{
	"data": {
		"1cf1e47b-50dd-4dd9-ae17-4e1deef855e1": {
			"status": "error",
			"message": "The recipient device is not registered with FCM.",
			"messageEnum": 7,
			"messageParamValues": [],
			"details": {
				"error": "DeviceNotRegistered",
				"errorCodeEnum": 3,
				"sentAt": 1686110797
			},
			"__debug": {}
		}
	}
}

@SleeplessByte
Copy link
Owner

Ok, and before it would give us the push token in THAT error and now it doesn't?

If so, I understand this PR and will happily look at it and get it merged :)

@ikusa
Copy link
Author

ikusa commented Jun 26, 2023

Sorry for taking while to reply

Based on the this library code I assumed yes it was returning the token in error. But I have no indication of way to confirm what's previous behavior exactly. The issue I saw here expo/expo#7795 indicate some people do get token but I also can't confirm are they hitting send endpoint or the check receipt endpoint.

From my latest test expo didn't include such token on checking receipt

@ikusa
Copy link
Author

ikusa commented Jul 6, 2023

By the way @SleeplessByte , sorry it took me so long to reply to you last time. If you have any more questions or need any changes after reviewing, I'll be able to respond pretty quickly going forward. Thanks again for taking a look at this!

@SleeplessByte
Copy link
Owner

@ikusa sorry I didn't get to this. I ended up being hospitalised and didn't touch a computer for half a year (see my GitHub profile).

Do you still think this is the best implementation? Should I test it or do you use it already?

Let me know where this is at so we can look at getting it merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants