Hello !
I'm trying to use Appwrite push Notification. I set up the Push Notification in Appwrite settings without any issue. I can also send push notification from the Appwrite console to my Android App.
Now I'm trying to send the push notification with an Appwrite function.
I have the following code:
import {Client, Users, ID, Messaging} from 'node-appwrite';
export default async ({req, res, log, error}) => {
const client = new Client()
.setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT)
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(req.headers['x-appwrite-key'] ?? '');
const users = new Users(client);
const messaging = new Messaging(client);
try {
const response = await users.list();
log(`Total users: ${response.total}`);
const message = await messaging.createPush(
ID.unique(),
"HI !",
"Hello",
[],
["68399458000c67552a3f"]
);
} catch (err) {
error(err);
}
return res.json({
motto: "Build like a team of hundreds_",
learn: "https://appwrite.io/docs",
connect: "https://appwrite.io/discord",
getInspired: "https://builtwith.appwrite.io",
});
};
But I get :
AppwriteException: Message with the requested ID could not be found.
at _Client.call (file:///usr/local/server/src/function/node_modules/node-appwrite/dist/client.mjs:278:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Messaging.createPush (file:///usr/local/server/src/function/node_modules/node-appwrite/dist/services/messaging.mjs:276:12)
at async Module.default (file:///usr/local/server/src/function/src/main.js:15:21)
at async execute (/usr/local/server/src/server.js:208:16)
at async action (/usr/local/server/src/server.js:225:7)
at async /usr/local/server/src/server.js:14:5
Do you know why ? I don't understand the error.
Thank you for your help 🙂
Version: 1.7.4
Recommended threads
- What is the best way to create personali...
So i'm experimenting with the messaging api and I want to create personalized emails not to advanced I just want to say "Dear <Users name>," ... you know stuff ...
- SMTP email templates break html
Hey, Im trying to create a custom template for the team invite email. The issue is the html invite I created (which works in normal emails and fake emails I sen...
- I am not getting "to" when email receive...
I am using cloud function to send an email when email received it doesn't have "to" email address. Please see attached image. My cloud function detail: built w...