Looking for help with writing server-side plugin

@bubble’s documentation is severely lacking for this. I had to enlist three different node/javascript experts, and the first two said it couldn’t be done or that Bubble’s documentation needed more details and to contact them for help.

The final person was able to figure it out after much trial and error with the below code being the end result that I hope will help others. So, I’d like to give a big recommendation to Nigel Peck on the Codementors site. If you need any help with coding, he knows his stuff. https://www.codementor.io/nigelbpeck

TLDR: You have to do a “return context.async…” with a callback.

function(properties, context) {

	var simpleParser = require('mailparser').simpleParser;

	var email = "From: 'Sender Name' <sender@example.com>\r\n"+
    "To: 'Receiver Name' <receiver@example.com>\r\n"+
    "Subject: Hello world!\r\n"+
    "\r\n"+
    "How are you today?";
    
return context.async(function(cb){
    simpleParser(email)
        .then(parsed => {
	        cb(undefined, { 
                subject: parsed.subject, 
                to: JSON.stringify(parsed.to.value), 
                from: JSON.stringify(parsed)
            });   
        })
        .catch(err => {
         
        cb(err);
        });
});
}
12 Likes