Pushing Podio

Fun Experiments pushing Citrix Podio to the limit so you can get more done.
... with a little help from GlobiFlow, ProcFu, and other friends ...

Email to Notion

- Posted in Uncategorized by

Getting things into Notion using email is an often requested feature that doesn't exist natively. However, if you have a ProcFu Gold plan or higher, you can leverage HTML widgets to get the job done.

The Notion Inbox

Most Notion users have an "Inbox" page. An easily-accessible page that is a dumping ground for information.

If you have an idea or come across something worth noting, you dump it into the Inbox page. Then when you have more time, you can go through the Inbox items and move them to their appropriate place.

/imggrv/20191205054127-5de8faf79ab05.png

Take note of the URL of this page as we're going to write a quick script to publish emails to it.

The ProcFu Widget

Even though we're not generating anything to display in ProcFu, we'll still need a widget.

Go to the Code Editor in ProcFu, and create a new code block.

In the footer, click on "Widget", and enable the widget.

Take note of the widget's email address. It will be in the format WIDGETID@catch.procfu.com.

Back to the code ...

The first thing we'll want to do is set any variables, which in this case is the URL of the inbox page from earlier.

$inbox = "https://www.notion.so/globi/Inbox-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

As with all widgets in ProcFu, any payload will be delivered in the $pf_payload variable, which is JSON-encoded text. So the first thing we'll need to do is decode the payload.

$data = json_decode($pf_payload, true);

Pro-tip: In situations like this when it's hard to interactively dump what's in the payload, use the set_var.pf script to save it to a variable, and then use the get_var.pf interactive script to recall it and investigate the data.

We'll start by creating a toggle block with the subject of the email as it's content.

$subject = $data["POST"]["subject"];
$blockId = call_pf_script("notion_block_create.pf", ["type" => "toggle", "text" => $subject, "parent_id" => $inbox]);

Then we'll create a text sub-block to the toggle with the text body of the email.

$text = $data["POST"]["stripped-text"];
$bodyId = call_pf_script("notion_block_create.pf", ["type" => "text", "text" => $text, "parent_id" => $blockId]);

For bonus points, we'll take any attachments and add them inside the toggle as well.

if ( isset($data["FILES"]) ) {
    foreach ( $data["FILES"] as $file ) {
        $json = json_encode($file);
        $fileBlockId = call_pf_script("notion_block_add_file.pf", ["parent_id" => $blockId, "file" => $json]);
    }
}

That's it. Not a huge amount of code now, is it? This is the entire code block:

// email_to_notion_inbox
// send email to widget address and it will create a new item in the Notion Inbox page
// will create new toggle with subject of email, and inner text with content and any attachments

// vars
$inbox = "https://www.notion.so/globi/Inbox-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

// decode payload
$data = json_decode($pf_payload, true);

// create toggle
$subject = $data["POST"]["subject"];
$blockId = call_pf_script("notion_block_create.pf", ["type" => "toggle", "text" => $subject, "parent_id" => $inbox]);

// create body as text inside toggle
$text = $data["POST"]["stripped-text"];
$bodyId = call_pf_script("notion_block_create.pf", ["type" => "text", "text" => $text, "parent_id" => $blockId]);

// attach any files
if ( isset($data["FILES"]) ) {
    foreach ( $data["FILES"] as $file ) {
        $json = json_encode($file);
        $fileBlockId = call_pf_script("notion_block_add_file.pf", ["parent_id" => $blockId, "file" => $json]);
    }
}

The Result

Now you can send an email into Notion very easily.

Compose an email to your widget's email address with subject, body, and optional attachments:

/imggrv/20191205054127-5de8faf7ca6a5.png

And it will appear in your Notion Inbox within seconds:

/imggrv/20191205054128-5de8faf816ac4.png

Comments

>