expo notifications while using customer.io

I am struggling to integrate notifications with my marketing automation tool customer.io.

I initially tried to use apn and firebase, which customer io supports. However, after migrating my app to expo, I was struggling to get notifications to work. Thus I tried using the expo SDK in my own backend and trigger the notifications through a webhook called from customer io. I was successful with this implementation. However, sometimes my users receive 10 notifications while I only trigger the notification once.

After speaking to customer io I was informed that their servers would retry any request, which was not resolved within 2 seconds. When testing locally through postman, I can see that my response time often is around 1 second, cf. the below picture. So my thought is that some users are receiving many notifications due to the endpoint’s response time is too slow. Thus customer io is retrying the request albeit the request is successful it just has not been resolved yet. All my code is pretty boilerplate from the expo sdk documentation for node.

      const notification = await Notification.create(insertableNotificaition)

      const ticket = await Notification.sendNotification(expo, message, notification.toJSON().id)

      return response.status(200).json(ticket);
      
      const reciept = await Notification.getReciept(expo, ticket.id, notification.toJSON().id)
'use strict'

/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model')
const NotificationTicket = use('App/Models/NotificationTicket')
const NotificationRecipt = use('App/Models/NotificationRecipt')

class Notification extends Model {

  static async sendNotification(expo, message, id) {
      let ticketMessage = expo.sendPushNotificationsAsync([message])
        .then(async response => {
          await NotificationTicket.create({
            notification_id: id,
            ticket_id: response[0].id,
            status: response[0].status
          })
          return response
        }).catch(async error => {
          await NotificationTicket.create({
            notification_id: id,
            error: JSON.stringify(error)
          })
        })

      return ticketMessage
  }

  static async getReciept(expo, recieptId, id) {
      let receipt = expo.getPushNotificationReceiptsAsync([recieptId])
      .then(async response => {

        await NotificationRecipt.create({
          notification_id: id,
          reciept: JSON.stringify(response)
        })

        return respose
      }).catch(async error => {
        await NotificationRecipt.create({
          notification_id: id,
          reciept: JSON.stringify(error)
        })
      })

      return receipt
  }

}

module.exports = Notification