Looking for help with writing server-side plugin

And here’s the same thing in async/await syntax instead of “thenable”, which I find a bit more readable…

return context.async( async callback => {
    try {
        let parsed = await simpleParser( email );
        callback( undefined, {
            subject : parsed.subject,
            to      : JSON.stringify( parsed.to.value ),
            from    : JSON.stringify( parsed.from.value )
        });
    }
    catch ( err ) {
        callback( err );
    }
});

And here’s a “template” example of using context.async(), which might be helpful to add to the docs (along with a better-worded description)…

return context.async( async callback => {
    try {
        let result = await myAsyncCall( args );
        callback( undefined, bubble_return_object );
    }
    catch ( err ) {
        callback( err );
    }
});

The undefined value is there because, per the docs, the callback expects both err and res arguments. The bubble_return_object represents the object defined in the Return values (output values) section of the plugin editor for server-side actions.

11 Likes