Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

New Discussions Twitter Feed

Say I wanted to setup a Twitter account that automatically tweeted every new thread that was Discussion, how would I do this?

Initially I thought to convert the RSS feed into a Twitter feed using Zapier or something, but the RSS contains more than just new discussions.



  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Sure! Look at that code and just ask if you have further questions:

    <?php defined('APPLICATION') or die;
    $PluginInfo['TwitterBot'] = array(
        'Name' => 'TwitterBot',
        'Description' => 'Post new discussions to Twitter',
        'SettingsPermission' => 'Garden.Settings.Manage',
        'SettingsUrl' => '/dashboard/settings/twitterbot',
        'Version' => '0.1',
        'Author' => 'You!',
        'License' => 'MIT'
    class TwitterBotPlugin extends Gdn_Plugin {
        // implement a setting screen so the admin can insert twitter api token
        public function settingsController_twitterBot_create($sender, $args) {
        // here's where you have to do most of the work
        public function discussionModel_afterSaveDiscussion_handler($sender, $args) {
            // You should consider adding a permission check here so that only discussions viewable by guests are published!
            // this is the info you might want to post to twitter
            $discussion = $args['Discussion'];
            $title = $discussion->Name;
            $body = Gdn_Format::to($discussion->Body, $discussion->Format);
            $author = $discussion->InsertName;
            $authorPhoto = $discussion->InsertPhoto;
            $date = $discussion->DateInserted;
            $category = $discussion->Category;
            $url = $discussion->Url;
            // here is something I found on how to do the twitter part of this task
  • Options

    Is this a good idea? You probably want to limit to set author an categories.

    There is more value on others choosing to share link through their twitter, rather than spamming your own twitter.

    grep is your friend.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    I totally agree! And I thought it would be a nice plugin to write and that's why I started to do right that. Here is the setting screen which reflects your concerns ;)

    I've added a "Only twitter announcements" to the settings because I think that might be a useful option.

    Now there is something to do on postController_discussionFormOptions_handler and I think some validation beforeSaveDiscussion would be good UX but the complexity is still okay.

    I do not use Twitter so that will be the hardest part to test =)

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Just in case I never finish it:

    It should be quite usable if it would be able to post to Twitter! ;) As far as I can tell that functionality is the only thing left, but I haven't made any tests. Don't know if I really should create a Twitter account just to create a plugin like that...
    I guess making the text which should be posted to Twitter configurable would be another nice feature.

    I think I'll invest some time more, but it is already a better skeleton than that of my first post in this discussion...

  • Options

    This forum is amazing O_O thanks for the quick work!

    Also yes @x00 I understand this isn't for everyone, but some people just gotta know what's going on ASAP!

  • Options

    Oh, didn't read your last post. So it's not actually working yet...?

    Also do you need to do this via a Twitter application, wouldn't it be simpler just to ask for a Twitter account credentials (I have no idea, just wondering out loud).

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    No, not working - just good looking ;)

    But I've registered a Twitter account and will look into how to do simple posts

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Oh, I'm such a Twitter noob! "Tweets" are limited to 140 characters, correct? So do you have an idea how a tweet should communicate discussion infos? "New discussion on %homepage%: "%discussion title%" posted by %user name% on %insert date%" would be waaaaay too long...

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    This one is fully working:

    Look at line 160 to customize your tweet.

  • Options
    hgtonighthgtonight ∞ · New MVP

    @R_J said:
    No, not working - just good looking ;)

    I have experience doing this. Where do I apply?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    It works! Wonderful! FYI I went with the following for the tweet:

    $tweet = ''.$title.' by '.$author.' '.$url.'';

    Only issue is after submitting the new discussion, a popup box appears with nothing written in it ... any ideas?

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    This might happen if you have entered a echo something, but I would say that this is an error. Add $Configuration['Garden']['Errors']['MasterView']= 'deverror.master.php'; and set $Configuration['Garden']['Debug'] = true; in your config.php and I assume there will be an error message in the empty popup.

    Maybe look first at the js error console of your browser.

  • Options
    edited August 2015

    Just added those two lines to the Config and the popup didn't appear at all! But the tweet didn't trigger either.

  • Options

    Actually it disabled the plugin, trying again...

  • Options

    Yeah adding that to config disables the plugin.

  • Options
    mtschirsmtschirs ✭✭✭
    edited August 2015

    Have you had a look at Twitter cards created by the Articles application? E.g. something like this in your discussion's HTML head might prove useful:

    <meta name="twitter:card" content="summary">
    <meta name="twitter:site" content="@name">
    <meta name="twitter:title" content="A Discussion Title">
    <meta name="twitter:description" content="Discussion Excerpt">
    <meta name="twitter:image" content="">

    Also, the way the current Vanilla 2.2 Twitter plugin extracts its tweets from a given discussion might give you helpful ideas :)

Sign In or Register to comment.