使用 NextJS 从 Onesignal 发送推送

Sending Push from Onesignal using NextJS

提问人:Erich García 提问时间:11/14/2023 更新时间:11/14/2023 访问量:18

问:

我正在尝试使用 NextJS + Onesignal 发送每日推送通知,但没有成功,我尝试了 @onesignal/node-onesignal 包和 API 包,但没有有效的解决方案。

我的代码:

import { NextResponse } from 'next/server';
// import * as OneSignal from '@onesignal/node-onesignal';
const sdk = require('api')('@onesignal/v11.0#7g0slo7voi53');

export async function GET(request) {

    const ONESIGNAL_APP_ID = 'aaa';
    const ONESIGNAL_API_KEY = 'aaa';

    sdk.createNotification({
        app_id: ONESIGNAL_APP_ID,
        included_segments: ['Subscribed Users'],
        // external_id: 'string',
        contents: {
            en: 'We are at $267.12 (CUP) and $1.11 (MLC). Follow the trend of CUP and MLC prices at CambioCUP.com 👌',
            es: 'Estamos en $267.12 (CUP) y $1.11 (MLC). Sigue la tendencia de los precios del CUP y MLC en CambioCUP.com 👌'
        },
        name: 'DAILY_RATE',
        // send_after: 'string',
        delayed_option: 'timezone',
        delivery_time_of_day: '9:00AM',
        throttle_rate_per_minute: 0,
        // custom_data: 'string'
    }, {
        authorization: 'Basic ' + ONESIGNAL_API_KEY
    })
        .then(({ data }) => console.log("DATA:", data))
        .catch(err => console.error("ERR:", err));

    return NextResponse.json({ sdk })
}

export const revalidate = 0; 

错误:

⨯ node_modules/@readme/openapi-parser/lib/validators/spec/openapi.js (165:14) @ syntax
 ⨯ unhandledRejection: {
  stack: 'SyntaxError: Validation failed. /paths/players?app_id={app_id}&limit={limit}&offset={offset}/get is missing path parameter(s) for {app_id},{limit},{offset}\n' +
    '    at validatePathParameters (webpack-internal:///(rsc)/./node_modules/@readme/openapi-parser/lib/validators/spec/openapi.js:135:19)\n' +
    '    at validateParameters (webpack-internal:///(rsc)/./node_modules/@readme/openapi-parser/lib/validators/spec/openapi.js:109:5)\n' +
    '    at eval (webpack-internal:///(rsc)/./node_modules/@readme/openapi-parser/lib/validators/spec/openapi.js:67:13)\n' +
    '    at Array.forEach (<anonymous>)\n' +
    '    at validatePath (webpack-internal:///(rsc)/./node_modules/@readme/openapi-parser/lib/validators/spec/openapi.js:55:7)\n' +
    '    at eval (webpack-internal:///(rsc)/./node_modules/@readme/openapi-parser/lib/validators/spec/openapi.js:22:13)\n' +
    '    at Array.forEach (<anonymous>)\n' +
    '    at validateSpec (webpack-internal:///(rsc)/./node_modules/@readme/openapi-parser/lib/validators/spec/openapi.js:18:34)\n' +
    '    at validateSpec (webpack-internal:///(rsc)/./node_modules/@readme/openapi-parser/lib/validators/spec.js:11:16)\n' +
    '    at OpenAPIParser.validate (webpack-internal:///(rsc)/./node_modules/@readme/openapi-parser/lib/index.js:155:13)\n' +
    '    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)',
  message: 'Validation failed. /paths/players?app_id={app_id}&limit={limit}&offset={offset}/get is missing path parameter(s) for {app_id},{limit},{offset}',
  toJSON: [Function: toJSON],
  name: 'SyntaxError',
  toString: [Function: toString]

差点放弃

ReactJS 推送 OneSignal

评论


答: 暂无答案