Send CloudwaysBot Notifications to Asana using Cloudways API

by Shahroze Nawaz  November 14, 2016

Bots are ideal for automating communication with customers and end users, mainly because of real time streaming of alerts and messages. Cloudways offers CloudwaysBot, a very smart assistant for servers and applications hosted on Cloudways Platform. The bot provides real time notifications that help users take actions for further optimizing servers and applications.

Send CloudwaysBot Notifications to Asana using Cloudways API

In this article I will demonstrate how to integrate CloudwaysBot and the popular task management application, Asana. Once you are done, you will be able to send CloudwaysBot notifications to Asana as a task.

Before starting, I assume that you already have an account on Cloudways. If you don’t, sign up for an account and launch your server. Next, launch your PHP application as shown in the GIF below.

 

Add the Application in Asana and Get Access Token

The next step of the process is to setup the application in Asana. This will generate an access token that would be used in the later cases.

Sign into Asana and click Profile > My Profile settings > Apps.

Click the Manage Developer Apps button and the heading Personal Access Tokens will appear.

 

Click Create New Personal Access Token. Enter a short description of the application and then click the Create button to get the access token.

Note: Save this token carefully as Asana does not display the token once created.

Add Asana PHP Wrapper Class

To use Asana API, I will use the Asana PHP wrapper class available at GitHub. This simple class was created by Adria Jimenez.

To install this class, run the following command in Composer

The Asana API class is now ready for use. Asana has a structural approach to task management with a hierarchy of workspaces, projects, and finally, tasks. I will fetch the workspace and projects from Asana.

Add require ‘vendor/autoload.php’; in index .php and initialize Asana by providing the access token. Validate it for the success response code.

Get all workspaces through this line:

Now using foreach() loop, I will print all workspaces and the included projects,

The following is the result of this code. The image shows that I have two workspaces and one project under Cloudways.com workspace.

I will use the workspace ID and the project ID to create a new task in the project.

Send CloudwaysBot Alerts as Tasks to Asana

To send CloudwaysBot alerts as task in Asana, I will setup a webhook in CloudwaysBot. But before that, I will add the code to get the response of the webhook.

This is a simple code snippet that will get the CloudwaysBot response and save it in $text.

Let’s create a task code and send this alert to the Asana Project. I will save project ID and workspace ID in variables.

I have created a task and get the ID of the task via $taskId = $asana->getData()->id; Next i have passed the $taskId and $projectId to assign the task to my particular project. Save the file now.

Setup the Webhook in CloudwaysBot

CloudwaysBot supports custom APIs and I will now create a webhook for the index.php file. I will use the the staging URL that is located in the Application Access Details tab.

Go to CloudwaysBot from the top navigation menu, click on the channels tab and then click the Add Channel button.

Select the API option from the drop down list.

Enter the complete URL of the index.php, set the Name of the channel and the status to Active.

Finally select the server and application alerts that you wish to send to Asana.

Now comes the exciting part. Click on the Save and Test channel button. The CloudwaysBot will send a test notification to the Asana project. If the notification goes through, the connection has been established.

Conclusion

In this article, I described how you could easily connect CloudwaysBot with Asana. This greatly streamlined project management tasks as all notifications generated by the CloudwaysBot are added as tasks to the Asana project. If you would like to contribute to the discussion or have a question, Leave a comment below!

 

Start Creating Web Apps on Managed Cloud Servers Now!

Easy Web App Deployment for Agencies, Developers and E-Commerce Industry

About Shahroze Nawaz

Shahroze is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. He’s always in search of new frameworks and methods to implement them. Besides his coding life, he loves movies and playing soccer with friends. You can email him at shahroze.nawaz@cloudways.com

Stay Connected:

You Might Also Like...