Skip to content

Huginn: Filter Retweets

A while ago I started using Huginn, as a replacement for IFTTT. That's going quite well. Huginn offers more features, integrations, and especially your chains (scenarios) can be as complex as you wish. IFTTT is quite limited in this area.

I use the Twitter integration to find certain Tweets. Now this does not only find native Tweets, but also finds every Retweet made for a native Tweet. Obviously I am not interested in duplicate content.

Huginn offers a way to filter out Retweets.

 

My first attempt was to look at the "retweeted" flag in the Event output from the search agent:

{
  "retweeted": false,
}

But this flag is always set to "false", I've never seen it set to "true". Not helpful.

Next I looked at the actual data emitted from the search agent. There is a difference between native Tweets and Retweets. The latter contains an additional hash:

{
  "retweeted_status": {
    ....
  }
}

The "retweeted_status" only appears in Retweets, and is there in native Tweets. That's useful, because a Huginn Trigger Agent can filter on that fact. Feed the output from the Twitter search into a new "Trigger Agent", and define the rules as follow:

{
  "expected_receive_period_in_days": "2",
  "keep_event": "true",
  "rules": [
    {
      "type": "field!=value",
      "value": "{{retweeted_status | default: 'somethingwhichwillnotbeinthetweet' }}",
      "path": "retweeted_status"
    }
  ],
  "message": "Not a RT"
}

 

  • keep_event: can be "true" or "false", depending if you want to keep your events after they are processed. I keep them around for a couple days, that gives me a chance to debug things, or re-emit them into the chain.
  • expected_receive_period_in_days: that should be set to a value matching how often you expect Tweets coming into this chain, the default is "2" but that might be too low. If there are no Tweets in two days, the Agent will set itself to non-operational.
  • message: can be anything, and is not really relevant in my case.
  • rules/type: The "field!=value" checks if a certain value is there.
  • rules/value: This is a bit of magic, because if the field is not present then the default will be used, which does not match, and therefore stops the filter at this point. The default value can be anything - as long as it will not appear in your Twitter event.
  • rules/path: The path the filter is looking for, in this case for "retweeted_status".

If the "retweeted_status" field is present, the Trigger Agent will proceed, emit the event into the next Agent (and add "message"). If the field is not present, processing stops here.

 

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.
Form options