Kogno
Search…
Scheduled Messages
Schedule and send messages in the future.

schedule(send_at=Time, tag=Symbol)

Platforms

Platform
Supported
Messenger
WhatsApp
Telegram

Usage

On Demand

user = User.first
user.notification.text "You'll receive this after 1 minute"
user.notification.scheduled(Time.now + 1.minute)

Send bulk

users = User.all
users.each do |user|
user.notification.text "This is an important announcement"
user.notification.template "main/announcement", {announcement_id: 1}
user.notification.scheduled(Date.tomorrow.to_time)
end

Reply

@reply.text "This is a reminder"
@reply.text "Take the cookies out of the oven"
@reply.scheduled(Time.now + 30.minutes)

Params

Name
Description
send_at Time
Required.
The date and time when message(s) will be sent.
tag Symbol
Optional. Scheduled message identification tag, can be any symbol.

Daemon

To send scheduled messages, there is a process that must be running. It can be started as follows:

In Background

kogno scheduled_messages start

In Foreground

kogno scheduled_messages fg

With the others processes from Kogno

kogno start
Kogno 1.0.0 server starting in production
Http: starting daemon..
Sequence: starting daemon..
Scheduled Messages: starting daemon..

Deleting and Re-Scheduling

If the tag argument has been included in the creation of a scheduled message, as the example bellow:
user = User.first
user.notification.text "This is a 24 hours reminder."
user.notification.scheduled(Time.now + 24.hours, :window_24h)
Then the following methods of the User model can be called:

destroy_scheduled_messages(tag=Symbol)

Deletes the scheduled message associated with the provided tag.
@user.destroy_scheduled_messages(:window_24h)

reschedule_message(tag=Symbol)

Re-Schedule the messages associated with the provided tag.
@user.reschedule_scheduled_message(:window_24h, Time.now + 23.hours + 55.minutes)

scheduled_message?(tag=Symbol)

Checks if there is a scheduled message associated with the provided tag.
@user.scheduled_message?(:window_24h)
Copy link
On this page
schedule(send_at=Time, tag=Symbol)
Platforms
Usage
On Demand
Reply
Params
Daemon
In Background
In Foreground
With the others processes from Kogno
Deleting and Re-Scheduling
destroy_scheduled_messages(tag=Symbol)
reschedule_message(tag=Symbol)
scheduled_message?(tag=Symbol)