我有这个功能
exports.webhook = functions.https.onRequest((_req: any, res: { send: (arg0: string) => void; }) => {
// It sends notification to a user
});
我希望在每天下午3点]执行此功能>。如何安排该功能每天在此时间运行?
我有一个发送通知的函数,函数名称为sendNotifications,如何从URL调用此函数并传递有效载荷变量title
和body
示例工作代码:
exports.sendNotifications = functions.firestore const payload = { notification: { title: no_of_followers2, body: desc + ' Notification body', icon: 'https://img.icons8.com/material/4ac144/256/user-male.png', click_action: `https://google.com`, } }; ... // some code const subscriber = doc.data().token; return admin.messaging().sendToDevice(subscriber, payload);
编辑2
我的功能:
exports.sendNoti_cal_log = functions.https.onRequest((_req: any, res: { send: (arg0: string) => void; }) => { const payload = { notification: { title: 'Notification Title', body: 'Notification body', icon: 'https://img.icons8.com/material/4ac144/256/user-male.png', click_action: `https://google.com`, } }; const subscriber = "evGBnI_klVQYSBIPMqJbx8:APA91bEV5xOEbPwF4vBJ7mHrOskCTpTRJx0cQrZ_uxa-QH8HLomXdSYixwRIvcA2AuBRh4B_2DDaY8hvj-TsFJG_Hb6LJt9sgbPrWkI-eo0Xtx2ZKttbIuja4NqajofmjgnubraIOb4_"; return admin.messaging().sendToDevice(subscriber, payload) });
现在,当我从URL调用此函数时,它可以工作,但没有任何响应,请参见屏幕截图:
我最后需要做的是,如何从参数传递title
并在函数中接收它。我的工作Https函数
//-------notification for calllogger exports.sendNoti_cal_log = functions.https.onRequest((req: any, res: { status: (arg0: number) => { (): any; new(): any; send: { (arg0: { status: string; }): void; new(): any; }; }; }) => { const payload = { notification: { title: 'Notification Title', body: 'Notification body', icon: 'https://img.icons8.com/material/4ac144/256/user-male.png', click_action: `https://google.com`, } }; const subscriber = "evGBnI_klVQYSBIPMqJbx8:APA91bEV5xOEbPwF4vBJ7mHrOskCTpTRJx0cQrZ_uxa-QH8HLomXdSYixwRIvcA2AuBRh4B_2DDaY8hvj-TsFJG_Hb6LJt9sgbPrWkI-eo0Xtx2ZKttbIuja4NqajofmjgnubraIOb4_"; return admin.messaging().sendToDevice(subscriber, payload).then((messagingResponse: any) => { res.status(200).send({status: "OK"}) }) });
编辑4(传递参数)
我已经在函数中传递了这样的参数:
exports.sendNoti_cal_log = functions.https.onRequest((req: any, res: { status: (arg0: number) => { (): any; new(): any; send: { (arg0: { status: string; }): void; new(): any; }; }; }) => { const param1 = req.params.param1; const payload = { notification: { title: 'Notification Title'+param1,
但是当我从URL传递它时,它在通知中显示为undefined:
我这样通过-
https://us-central1-fir-crud-5b378.cloudfunctions.net/sendNoti_cal_log?param1=Hello
我有此函数exports.webhook =函数。https.onRequest((_ req:any,res:{send:(arg0:string)=> void;})=> {//它向用户发送通知}) ;我希望这个函数是...