I like this webpush module, but I have trouble making special rules if after creating new node page content on rules action to send notification via webpush.

<?php
/**
 * Implements rules_action_info().
 */
function webpush_rules_action_info() {
  return array(
    'webpush_notification' => array(
        'group' => t('Webpush notification'),
        'label' => t('Webpush send notification'),
        'parameter' => array(
            'title' => array(
                'type'  => 'textfield',
                'label' => t('Webpush Title'),
                ),
            'body'  => array(
                'type' => 'textfield',
                'label' => t('Webpush Body'),
                ),
            'link'  => array(
                'type'  => 'textfield',
                'label' => t('Webpush Link'),
                ),
        ),
    ),
  );
}

?>

Thank you in advance

CommentFileSizeAuthor
#5 webpush rules.jpg509.96 KBParanoidIsBack

Comments

ParanoidIsBack created an issue. See original summary.

efpapado’s picture

Status: Active » Needs work

Great idea, please provide a patch.

ParanoidIsBack’s picture

Issue summary: View changes
Issue tags: +Webpush
gisle’s picture

Issue tags: -Webpush

Before adding tags read the issue tag guideline: https://www.drupal.org/node/1023102 Do NOT use tags for adding random keywords or duplicating any other fields.

ParanoidIsBack’s picture

StatusFileSize
new509.96 KB

Sorry for that and thank you for the information.

below this fixes the code in webpush.rules.inc:

<?php
/**
 * Implements rules_action_info().
 */
    function webpush_rules_action_info() {
      return array(
        'webpush_notification__create_entity' => array(
            'group' => t('Webpush notification'),
            'label' => t('Webpush send notification'),
            'parameter' => array(
                'title' => array(
                    'type'  => 'text',
                    'label' => t('Webpush Title'),
                    ),
                'body'  => array(
                    'type' => 'text',
                    'label' => t('Webpush Body'),
                    ),
                'link'  => array(
                    'type'  => 'text',
                    'label' => t('Webpush Link'),
                    ),
            ),
        ),
    );

    function webpush_notification__create_entity($title, $body, $link) {
        $entity_type = 'webpush_notification';
        $entity = entity_create($entity_type,[
            'title' => $title,
            'body' => $body,
            'link' => $link,
            'created' => REQUEST_TIME,
            ]);        
        $entity->save();
    return $entity;
    }    
}

?>

example
in experiments that are marked red, this is made through content type and execution by rules of action but is declared to have failed: D there is no notification wherever sent

efpapado’s picture

in experiments that are marked red, this is made through content type and execution by rules of action but is declared to have failed: D there is no notification wherever sent

Your flow is wrong: Creating a webpush_notification entity does not trigger sending of this notification.
If you use the function provided by the module, it will create the entity and also send the notification.

ParanoidIsBack’s picture

If you use the function provided by the module, it will create the entity and also send the notification.

(as in the picture marked in green it was successfully sent)
but how to write code or create a trigger on webpush.rules.inc to make this "rule action" send a notification?

Thank you for enlightening

esolitos’s picture

You could take a look at what is done in webpush_admin_send_form_submit().

We would probably need to duplicate the code for that, or even better extract the fuctionality from the form submit and make it available as API.