How to test a Server Side plugin?

To be fair, though, the execution environments are a bit different. That said, the cb argument in the webtask example is a “callback”. Anyway, try the following…

function( properties, context )
{
    var Twitter = require('twitter');

    var client = new Twitter({
        consumer_key: context.keys["Consumer Key"],
        consumer_secret: context.keys["Consumer Secret"],
        access_token_key: properties.access_token,
        access_token_secret: properties.access_token_secret
    });

    return context.async( async callback => {
        try {
            await client.post('statuses/update', {status: 'I am a tweet'}, function(error, tweet, response) {
                if (error) console.log( 'Error: ' + error.message );
                console.log( 'Tweet: ' + tweet );
                callback( undefined, { the_tweet: tweet.text, raw_resp: response.body } );
            });
        }
        catch ( err ) {
            callback( err );
        }
    });         
}

It’s untested but probably close tested and works. It does assume the_tweet and raw_resp are defined under Fields Return Values for the plugin.

2 Likes