Accepting a subscription offer by installing a ruleset
If you didn’t have a rule in your pico at the time it received a subscription offer, all is not lost.
You can install a ruleset like the one shown here to accept it after the fact.
This ruleset checks to make sure it is a subscription you expected (lines 8-9), accepts it (line 14), and then finally deletes itself (line 16). So all you need to do is install the ruleset in your pico.
ruleset acceptance {
meta {
use module io.picolabs.subscription alias subs
}
rule initialize {
select when wrangler ruleset_installed where event:attr("rids") >< meta:rid
pre {
s = subs:inbound("Tx_role","participant list")
.filter(function(i){i{"Rx_role"}=="participant"})
.head()
}
if s then noop()
fired {
raise wrangler event "pending_subscription_approval" attributes s
} finally {
raise wrangler event "uninstall_ruleset_request" attributes {"rid": meta:rid }
}
}
}
If you install this manually in the developer UI, it won’t even appear in the Rulesets tab (of course, in that case, you could have just accepted it manually in the Subscriptions tab). In the project from which this came, the acceptance
ruleset was installed programmatically in a number of child picos to which a subscription offer had previously been made, thus forcing them to establish the subscription.
Copyright Picolabs | Licensed under Creative Commons.