Use @Action

What is an action? It is a string of characters sent to the script, formed as follows:

action?nameAction=value

For example, we can use them if we want [create a persistent menu on Facebook Messenger] (https://developers.facebook.com/docs/messenger-platform/send-messages/persistent-menu), the JSON will be the following :

{
  "persistent_menu":[
    {
      "locale":"default",
      "call_to_actions":[
        {
            "title":"Main Menu",
            "type":"postback",
            "payload": "action?menu"
        }
      ]
    }
  ]
}

When the user clicks the Main Menu button, an action?menu message will be sent to the script, of course invisible to the user.

Action Decorator

To start a function in the script, let's use the decorator @Action():

@Action('menu')
menu() {
    > My menu
}

If a value is sent

For example, with action?menu=game, we can use the magic variable action

@Action('menu')
menu() {
    > Menu is { :action } // displays "Menu is game"
}

Last updated