【发布时间】:2020-02-15 02:25:22
【问题描述】:
我正在使用 web-push 库通过节点服务器发送推送通知。目前,我只能从后端发送标题。有没有办法从后端发送图像?
【问题讨论】:
标签: javascript node.js push-notification web-push
我正在使用 web-push 库通过节点服务器发送推送通知。目前,我只能从后端发送标题。有没有办法从后端发送图像?
【问题讨论】:
标签: javascript node.js push-notification web-push
这是发送带有图像的通知的示例函数:
function sendPushNotification(req, res) {
const subscriptionId = req.params.id;
const pushSubscription = subscriptions[subscriptionId];
webpush
.sendNotification(
pushSubscription,
JSON.stringify({
title: "your title",
text: "your text",
image: "path/to/image.jpg",
tag: "new...",
url: "/your-url.html"
})
)
.catch(err => {
console.log(err);
});
res.status(202).json({});
}
这来自 Lorenzo Spyna,它解释了如何在这个 tutorial 中进行操作,您可以在 github 的 this project 中查看所有代码
【讨论】: