1

I have a D7 site running with Organic groups, rules, VBO, panels, badges, private-message modules ... and a bootstrap sub-theme (js, jQuery update, ...) working in all browsers, ios & android, i need to alert users with a beep sound when new OG content is created (or any rules reaction) by a custom module named beepsound module.

What I have:

• Rules event: create new content

• Rules condition: my contentype with some fields.

• Rules action: Loop: all OG group members, loop action: see code below

"beepsound module" must have UID variable to target a specific OG member.

I have manage to have my beepsound as an action in rules, it targets UID, it display a personalised message corectly, also, message is displayed 5 times (when tiggered when mycontentype is being viewed), meaning rule is triggered 5 times, here are my-module code files, dot module file exist but is empty (and not displayed here), If i run this rule with current-user, it works (makes a beep), but not in my OG loop, what it is wrong?

beepsound.info MODULE

name = Beep sound by rules module 
description = Module to add a beep sound action in rules
package = Custom
version = 7.01
core = 7.x
dependencies[] = rules

beepsound.rules.inc MODULE

/**
* Implement hook_rules_action_info()
* Declare any meta data about actions for Rules
*/

function beepsound_rules_action_info() {
$actions = array(
'beepsound_action_beepsound_user' => array(
    'label' => t('Make a beep sound'),
    'group' => t('sound'),
    'parameter' => array(
        'account' => array(
            'type' => 'user',
            'label' => t('User to beep'),
            ),
    ),
  ),

);

  return $actions;
}

/**
 * The action function for produce sound
 */

function beepsound_action_beepsound_user($account) {
    drupal_set_message(t('Hello @username',
 array('@username' => $account->name)));
    ?><audio autoplay="autoplay">
      <source src="/sites/all/modules/beepsound/A-tone.ogg" type="audio/ogg">
      <source src="/sites/all/modules/beepsound/A-Tone.mp3" type="audio/mp3">
    </audio><?php
} 

here is my rule

{ "og_og_new_content_notification_message" : {
"LABEL" : "OG new content notification message",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "OG" ],
"REQUIRES" : [ "og", "rules", "privatemsg_rules", "beepsound" ],
"ON" : { "node_insert" : [] },
"IF" : [ { "og_entity_is_group_content" : { "entity" : [ "node" ] } } ],
"DO" : [
  { "og_get_members" : {
      "USING" : { "group_content" : [ "node" ] },
      "PROVIDE" : { "group_members" : { "group_members" : "List of group members" } }
    }
  },
  { "LOOP" : {
      "USING" : { "list" : [ "group-members" ] },
      "ITEM" : { "list_item" : "Current list item" },
      "DO" : [
        { "privatemsg_rules_new" : {
            "USING" : {
              "recipient" : [ "list-item" ],
              "author" : [ "node:author" ],
              "subject" : "\u0022[node:title]\u0022 a sido creado. ",
              "body" : "\u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E Por favor haz clic aqu\u00ed para ver su contenido\u003C\/a\u003E"
            },
            "PROVIDE" : { "thread_id" : { "thread_id" : "ID of new thread" } }
          }
        },
        { "beepsound_action_beepsound_user" : { "account" : [ "list-item" ] } },
        { "drupal_message" : { "message" : "beep beep, usuario: \u0022[list-item:uid]\u0022" } }
      ]
    }
  },
  { "drupal_message" : { "message" : "Se ha enviado un mensaje a todos los miembros del departamento." } }
]

} }

1
  • Hi, we can't help you to decide which method you want to use, but once you have, and if you're struggling to implement that method with rules, please ask a specific question about that. Many thanks
    – Clive
    Commented Sep 13, 2016 at 8:39

1 Answer 1

1

In order to send a message to users other than the current user, you will need to do some additional processing. drupal_set_message sets a message in the current user session. It does not set a message in another user's session.

Some possible approaches include a push or pull notification type system. For example, the server can push updates to the client using something interesting like a Service Worker (advanced). Alternatively, the client can poll the server periodically, via ajax type request to get message updates.

2
  • Hi David, thanks for your answer. Can you please be more specific? I understand that "rules" are on server side, and my "beep sound" is on user side.
    – pinueve
    Commented Sep 18, 2016 at 14:45
  • Hi @pinueve, you may need to be more specific with your question. Commented Sep 19, 2016 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.