One of our favourite Project Management plugins for WordPress is the excellent WP Project Management by Tareq Hasan. The free version of the plugin gives the user a reasonable start and there are some neat commercial addons as well as a pro version of the plugin which offer more functionality.
However, as a small developer team we have also been looking at improving its functionality within our working environment, and if, like us, you have a Google hosted email service for your domain, and rely on Google Drive for sharing documents then you will find our little integration with the Google Tasks quite handy.
Our Google Apps Script integrates into your Drive account, scanning your Gmail to look out for mails sent by the WP Project plugin when a new task or comment has been assigned to you. The mail is scanned for the link to your worpress dashboard where you can view the details of the task or the comment. The link is embeded (as a goo.ly shortened URL) into your Task title, allowing you to quickly see your latest tasks and loading them up in your browser with a single click.
Here is what you need to do to get it to work…
Get the Google Script
Copy the following spreadsheet (Open the linked Google Spreadsheet, and go to the menu File->Make Copy in Google Drive). Once you have copy, you can save it (menu File->Move to Folder) under a specific folder in your Google Drive (Some place safe where it unlikely to get deleted by mistake). You can also rename it if you want.
Open the Script Editor
Open the new copy and select the menu Tools->Script Editor, “Copy of Gmail Task Integration” and note the following lines at the top of the Code.gs script file:
TASKLIST = “Projects”;
TASKPROJECT = “Others”;
LABEL_PENDING = “Projects/Tasks”;
LABEL_DONE = “Projects/Tasks/Done”;
The first line is the name to the task list under which your Google tasks links will be filed.
The send line is the Project name in case it it not defined in the email (this is rarely the case…).
The third line is the gmail label under which the email will archived when they reach your inbox, and finally the fourth line is the gmail label to which the script will move the mails that have been converted into tasks.
Feel free to change any of the above.
Accept Google API terms
There is a lot of freebies given by Google to use their services, but usually restrained with some quotas. You need to accept these for the services uses in this script, namely the Tasks service and the URL Shortener service.
In the Script Editor that you opened in the previous step, select the menu Resources -> Advance Google Services Switch and verify that the Tasks & URL Shortener serivces are ‘ON’ in the table that opens.
At the bottom of the table open the link “Google Developer Console”, (you may be required to accept the terms of use of Google Apps Script in general if this is the first time you use it). Then find the Tasks API in the list make sure it is ‘ON’, if it ‘OFF’, click on the ‘OFF’ button to enable it, agree to all the terms. Repeat this for the URL Shortener API.
Note: you will now required to register a project with Google and setup a credit ard payment to access the APIs. Google still gives free access to a limited API calls each month, but requires you to setup a payment facility.
Create a new version
Back to Script Editor screen, slect Menu File->Manage Versions and save a new version called “Mail Task Filter”
Set Triggers for the script
Set up the triggers which will fire the script at regular intervals to check for new mails. In the Script Editor menu select Resources->Current Triggers
We set it up to run thrice-a-day, early morning in case we’ve been working late into the night and want our office colleagues to see our new tasks when they get into office.
Once at lunch time for morning session work, and finally one at the end of the day. Again, it’s quite self-explanatory so feel free to adjust it as per your needs.
Create Gmail filters & labels
Create filter & labels in your Gmail account. If you have changed the Script constants above in the script file Code.gs in the section “Open the Script Editor”, then make sure you use those values.
Create a labels:
- “Projects”
- “Tasks” nested under Projects
- “Done” nested under Tasks
Create a new filter:
from: <the email address from which your wordpress servers notifies you of new tasks and comments>
Subject: [<title of your wordpress site>]
Check box: Skip Inbox (archive it)
Check box: Apply label “Projects/Tasks”
save the new filter.
Test it!
Send yourself a task from the WP Project Manager plugin… In the Script Editor, Run the project, if you have any errors, leave a comment below.
Further reading
- This work was initially inspired from an online tutorial on DJ Adam’s blog.
-
I initially wanted to create parent task for each Projects, and each time a new task or comment is filed under that Project, a child tasks would be created using the indent functionality of Google Tasks, but unfortunately I didn’t manage to get it to work, the Google Script API is still in beta mode. If you have an idea how to do this, maybe you can respond to my question on Stack Overflow.I have actually managed to figure this one out and the code has been updated in the above links. - Google Tasks allows tasks to be created from an email, and the email then appears as an attachment and link in the newly created tasks. This was a neat functionality that I tried to reproduce without any success until I realised that the API only exposes the read only part of this functionality. So this may change in the future and that would a nice update to this script. You will find commented out blocks of code in the script where I attempted this. As a work around I inserted the shortened url to the task in the Worpress dashboard within the title of the tasks.
- I found a bug in the Google Script API. Email messages are encapsulated by the GmailMessage class. A method getBody() allows to retrieve the html version of the mail body. However, the method corrupts URL embedded within the body text by replacing ‘&’ signs with ‘&’. I filed the bug in the issue tracker, feel free to vote for it.
Leave a Reply