使用 customer.io 时的博览会通知

时间:2021-02-17 13:54:35

标签: javascript react-native expo

我正在努力将通知与我的营销自动化工具 customer.io 集成。

我最初尝试使用客户 io 支持的 apn 和 firebase。但是,在将我的应用程序迁移到 expo 后,我很难让通知正常工作。因此,我尝试在自己的后端使用 expo SDK 并通过从客户 io 调用的 webhook 触发通知。我在这个实现上取得了成功。但是,有时我的用户会收到 10 条通知,而我只触发一次通知。

在与客户 io 交谈后,我被告知他们的服务器将重试任何请求,但在 2 秒内未得到解决。通过邮递员进行本地测试时,我可以看到我的响应时间通常在 1 秒左右,参见。下图。所以我的想法是,由于端点的响应时间太慢,一些用户收到了很多通知。因此,客户 io 正在重试请求,尽管请求成功但尚未解决。我所有的代码都来自于节点的 expo sdk 文档。

 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

[![Response time][1]][1]

0 个答案:

没有答案