Skip to content
This repository was archived by the owner on Mar 31, 2021. It is now read-only.

adds email model, adds outlook as data source#401

Merged
corradio merged 20 commits intoelectricitymaps:masterfrom
baywet:feature/outlook
Jun 29, 2020
Merged

adds email model, adds outlook as data source#401
corradio merged 20 commits intoelectricitymaps:masterfrom
baywet:feature/outlook

Conversation

@baywet
Copy link
Copy Markdown
Contributor

@baywet baywet commented May 19, 2020

Email contributes to carbon emissions, ideally people should only send and receive the emails they absolutely need and unsubscribe from what they don't need.
This pull request adds support for an email model and integrate with Outlook (Office 365 & consumer).
In addition, a lot of sites/apps do not provide APIs to integrate activities easily but send emails instead. Parsing those emails is a good way to extract additional activities automatically. This PR lays the infrastructure to do so (with an example with IKEA)

@baywet baywet marked this pull request as ready for review May 31, 2020 18:41
@baywet
Copy link
Copy Markdown
Contributor Author

baywet commented May 31, 2020

To create the app registration:

You'll need a live/outlook/office 365 account to perform the following setps.

  1. Go to the azure portal
  2. Click on Azure Active Directory
  3. Click on App Registrations
  4. Click on New registration
  5. Enter a name for the application
  6. Select the Multi-tenant and personal accounts option
  7. Click Register
  8. Go to API Permissions
  9. Click Add Permission
  10. Select Microsoft Graph and Delegated permission
  11. Search for Mail.Read
  12. Select the permission and click Add permission
  13. Go to Authentication
  14. Click Add platform
  15. Add the iOs platform and Android platform (or the single page application depending on your case)

I don't have a lot of experience developing native applications, the SPA option could be the right one as well depending on how your app is setup. If you go the SPA route use the deep link to your application as the Redirect URI (you can always add more once the platform is added).

When testing with the playground:

  1. Select platform and add http://localhost:3000/oauth_callback as the redirect URL.
  2. Go Certificates and secrets and generate a new secret.
  3. Copy the value of the secret to MSGRAPH_CLIENT_SECRET in env,json
  4. Go to Overview and copy the application id
  5. Paste the value to MSGRAPH_CLIENT_ID in env,json

@martincollignon
Copy link
Copy Markdown
Contributor

This is very impressive - @corradio I envision potential privacy issue, can you advise?

@corradio
Copy link
Copy Markdown
Member

This is very impressive - @corradio I envision potential privacy issue, can you advise?

I've looked briefly at the code and I don't see any privacy issues introduced.
I would however not recommend creating one activity per email (as it would create a lot of bubbles with a negligible footprint) and instead create activities of type ACTIVITY_TYPE_PURCHASE when a purchase has been detected from an email.
This will also enable the user to edit the activity without us having to do any more UI work.

@baywet
Copy link
Copy Markdown
Contributor Author

baywet commented Jun 11, 2020

so you would create one purchase a day/week with one item and the quantity being the number of emails basically?

Is it possible to purchase something at zero dollars today in the UI/model?

The reason why I started a digital category is because I also wanted to add online storage (onedrive, box etc...) and online video watching (youtube...) as sub-items of those categories.

@corradio corradio self-requested a review June 12, 2020 06:21
@corradio
Copy link
Copy Markdown
Member

so you would create one purchase a day/week with one item and the quantity being the number of emails basically?

Is it possible to purchase something at zero dollars today in the UI/model?

The reason why I started a digital category is because I also wanted to add online storage (onedrive, box etc...) and online video watching (youtube...) as sub-items of those categories.

The footprint would be so small (even for a week) that I would refrain against doing anything with the number of emails themselves (anything <1kg will clutter the UI up without contributing significantly).
The second issue is that we will need to change the UI (to enable editing) and that is not something we will be able to prioritise in the near future.
However, I think the vision of adding a vertical called "digital" makes sense. We're just not ready yet on our side ;-) We might work on it in Q3/Q4 by adding the footprint of Azure/AWS/GCP.

Finally, it makes totally sense to start working on email parsers that can extract activities from emails (such as purchases). That is something we can do with 0 changes to the UI.
Hence my suggestion: I would not create digital activities with the number of emails, but instead I would create activities extracted from emails (e.g. purchases) and encourage others to start writing more advanced parsers!

Does that make sense?

@baywet
Copy link
Copy Markdown
Contributor Author

baywet commented Jun 13, 2020

It does, couple of questions:
Would you prefer me to leave the code in place for email activities but disable it (not call it) or remove it all together at this point?

What about other digital activities such as watching online videos I wanted to add?

@corradio
Copy link
Copy Markdown
Member

corradio commented Jun 15, 2020

I suggest commenting out / disabling the code that creates an activity per email (but keep the code that extracts purchase activities)
Regarding the footprint of online videos, you could read this thread that we started a while back: #46
For now, it seems like the footprint is too small and will impact performance of the app (if we create a bubble for each video watched/email received).
But maybe it's worth making some calculations to make sure it's worthwhile.

@baywet
Copy link
Copy Markdown
Contributor Author

baywet commented Jun 20, 2020

I have disabled the generation of activities per email but kept the parsing part.
I'm going to take a look at the video part whenever I get the time.
For the bubble issue: there's a simple solution -> aggregate any activity of the same type for the month that is under 100 g CO2 eq before you generate the bubble, and add an indicator that the bubble is aggregated (behold my paint skills).
Screenshot_20200620-140825

Copy link
Copy Markdown
Member

@corradio corradio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone through the code and added a few comments.
Thanks for pushing through here! It's quite exciting to see this come to life.

@corradio corradio requested a review from madsnedergaard June 21, 2020 10:54
@baywet
Copy link
Copy Markdown
Contributor Author

baywet commented Jun 21, 2020

No worries, thanks for your help. Replied to some of your comments with questions. I'll make the changes once I have the answers to those.

Co-authored-by: Olivier Corradi <1655848+corradio@users.noreply.github.com>
@baywet baywet requested a review from corradio June 21, 2020 22:15
Copy link
Copy Markdown
Member

@madsnedergaard madsnedergaard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me, awesome work! Leaving final review for @corradio :)

@corradio corradio merged commit 14e12f2 into electricitymaps:master Jun 29, 2020
@baywet baywet deleted the feature/outlook branch June 29, 2020 13:31
@baywet
Copy link
Copy Markdown
Contributor Author

baywet commented Jun 29, 2020

Thanks team! I can't wait to see people implementing more email providers! I'll try to get started on GMail soon.

@corradio
Copy link
Copy Markdown
Member

Thanks team! I can't wait to see people implementing more email providers! I'll try to get started on GMail soon.

Ofcourse! I think GMail requires a paid access though..

@baywet
Copy link
Copy Markdown
Contributor Author

baywet commented Jul 19, 2020

@corradio juste checking in here. How close are we to see that in the app? The new design looks great by the way!

@madsnedergaard
Copy link
Copy Markdown
Member

@corradio juste checking in here. How close are we to see that in the app? The new design looks great by the way!

Hey @baywet, we had to do some changes to make it work (#427) and some internal updates as well, but that has been done and it's now being QA tested internally - it will be included in next release within a few days, so I'll let you know when it's out :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants