I'm building a notifications trigger method and wanted to be run 3 times per day at specific times.
I have checked the documentation but didn't understand that regex code for and how to customize it as I need it!
Now my method looks like this: ( it now runs evey min at second 45th for testing ) I need it for example runs at 6pm, 8pm, 11pm every day
@Cron('45 * * * * *')
async sendNotificaiotns() {
console.log('sending notification');
try {
const randomArticle = await this.articleRepository
.createQueryBuilder()
// .select("id")
// .getMany();
// .select("id")
.orderBy("RAND()")
.limit(1)
.getOne();
const input = new NotificationBySegmentBuilder()
.setIncludedSegments(['Active Users', 'Inactive Users'])
.notification() // .email()
.setAttachments({
data: {
...randomArticle,
},
big_picture: encodeURI(randomArticle.image)
})
.setHeadings({ 'en': randomArticle.title })
.setContents({'en': randomArticle.excerpt })
.build();
console.log(randomArticle);
await this.oneSignalService.createNotification(input);
} catch (e) {
console.log(e);
}
}