-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gmailpush initialize function not getting called using example code #11
Comments
Thank you. I put a good deal of efforts into writing this doc. By the way I think my choice of word initialize for For Node Schedule it's not part of Gmailpush but you can add it to your code like example below, or do you think it should be included in Gmailpush? const schedule = require('node-schedule');
const fs = require('fs').promises;
...
app.post(
'/pubsub-push-endpoint',
express.json(),
(req, res) => {
res.sendStatus(200);
const email = gmailpush.getEmailAddress(req.body);
const token = users.find((user) => user.email === email).token;
gmailpush
.getMessages({
notification: req.body,
token
})
.then((messages) => {
console.log(messages);
fs.readFile('./gmailpush_history.json')
.then((result) => {
const prevHistories = JSON.parse(result);
const prevHistory = prevHistories.find((prevHistory) => prevHistory.emailAddress === email);
schedule.scheduleJob(new Date(prevHistory.watchExpiration - 1000 * 60 * 30), async () => {
prevHistory.watchExpiration = await gmailpush._refreshWatch();
fs.writeFile('./gmailpush_history.json', JSON.stringify(prevHistories));
});
});
})
.catch((err) => {
console.log(err);
});
}
); |
I'm a little confused about this. From what I understand of Google's PubSub API, it doesn't start sending notifications to the subscriptions until a server starts watching the topic. But the example code doesn't start watching until there is a call to
I'm not sure of all the use-cases of a library like this, but in my opinion, there could be 2 convenient things the library could do to help with this:
What do you think? I might have some misconceptions about how this library works, so let me know if I'm overcomplicating this in my head! My use case is setting up a personal email watcher so that I can run scripts whenever I get an email in my personal inbox. That's why I want to start watching and never stop watching. |
I might be able to help with a basic implementation of this! I'm sure I could dive into the library and understand the basics in an hour or two. But given the sample code you wrote, I'm sure the easier fix that I suggested above could hopefully be implemented pretty quickly. Just let me know! |
For "1. An initial call to watch() to kick it off", I will provide For "2. An inbox update once every 7 days so that it knows to make another call to watch()", I will implement Node Schedule into Gmailpush to call Thank you for your offer! But I think this should be done without taking your time. |
Makes sense! So I can just use |
Okay, I just looked through the code, and I think I understand what you are saying when you said that the |
You don't have to call By the way, looking into my code I had written one year ago I realized that json file is not necessary and information contained in it could be attached to Gmailpush class. It could make this library more usable. So next version would be either 1.1.0 or 2.0.0. |
I followed the example code provided line for line, but it didn't seem like the topic was ever getting watched (and no history file was created). I debugged a little bit, and I don't think
this._initialize()
is being called using the setup that was provided in the readme. I'm sure I'm missing something simple, but any help on this?From poking around the source code, I noticed that the initialize function takes in a notification, but I'm still not sure when it's meant to be called 🤔
The text was updated successfully, but these errors were encountered: