Kogno
  • Introduction
  • Getting Started
    • Configuration
    • Starting the Server
    • Messenger Configuration
    • Telegram Configuration
    • WhatsApp Configuration
    • NLP Configuration
  • Conversation Class
  • Contexts
    • Blocks
      • before_anything
      • postback
      • deep_link
      • command
      • any_attachment
      • regular_expression
      • keyword
      • any_number
      • any_text
      • intent
      • entity
      • membership
      • recurring_notification
      • everything_else
      • after_all
    • Sub Contexts
    • Routing
    • Sequences
    • Conversational Forms
  • Replies / Notifications
    • text
    • button
    • quick_reply
    • raw
    • list
    • carousel
    • url
    • typing
    • image
    • video
    • html
    • markdown
    • contact
    • location
    • recurring_notification_request
    • messenger_generic_template
    • whatsapp_template
  • Templates
  • Models
    • User model
  • Scheduled Messages
  • Telegram Inline Query
  • Command Line
  • Global Methods
  • Internationalization
Powered by GitBook
On this page
  • recurring_notification(event=Enum(:granted, :removed), &block)
  • Platforms
  • Usage
  • Data param example
  • Sending Notifications

Was this helpful?

  1. Contexts
  2. Blocks

recurring_notification

This block will be executed when a user has granted or removed permissions to receive recurring notifications from Messenger.

PreviousmembershipNexteverything_else

Last updated 2 years ago

Was this helpful?

recurring_notification(event=Enum(:granted, :removed), &block)

Platforms

Platform
Supported

Messenger

WhatsApp

Telegram

Recurring notification request

In order to make this event occurs, a notification request must be send to the user by calling the method .

Read more about Messenger recurring notifications in the .

Usage

class MainContext < Conversation

  def actions
  
    recurring_notification :granted do |data|
      @reply.text "Thanks for subscribing to #{data[:frecuency]} notifications"    end

    recurring_notification :removed do |data|
      # Here you can handle the removed permission event
    end

    payload :get_started do
      @reply.text "Welcome!"
      @reply.notification.recurring_notification_request(
        {
          title: "Whould you like to receive weekly notifications from us?",
          image_url: "https://previews.123rf.com/images/aquir/aquir1909/aquir190907932/129839413-bot%C3%B3n-de-suscripci%C3%B3n-suscr%C3%ADbete-letrero-rojo-redondeado-suscribir.jpg?fj=1",
          payload: :subscribe,
          frequency: :weekly,
          reoptin: true
        }
      )
    end
    
  end
  
end

Data param example

On permissions granted

{
  token: "XXXXXXXXXXXXXXXXXXXXXX",
  frecuency: "WEEKLY",
  expires_at: "2023-03-21 12:27:09 UTC",
  token_status: "NOT_REFRESHED",
  timezone: "UTC",
  status: "active"
}

On permissions removed

{
  token: "XXXXXXXXXXXXXXXXXXXXXX",
  frecuency: "WEEKLY",
  expires_at: "2023-03-21 12:27:09 UTC",
  token_status: "NOT_REFRESHED",
  timezone: null,
  status: "stopped"
}

User's Subscription Status

The user's subscription status can be verified by calling the messenger_recurring_notification_data() method in the User model.

Sending Notifications

To send a notification using the recurring notification token, just call send_using_token() method instead of send().

user = u = User.where(platform: "messenger").first
user.notification.text "Hello World!"
user.notification.send_using_token()
recurring_notification_request()
official documentation