How To Capture WATI Chats On Zoho Desk As Tickets?

Capture all new WATI chats on Zoho Desk as tickets for Free

Capture New WATI Chats On Zoho Desk As Tickets For Free

This article will outline how to use Zoho Desk to capture new chats from WATI.

If you are already using Zoho Desk, it will now become a single source of all your customer queries. For others, Zoho Desk offers a ticketing solution with advanced features. For instance, you can now assign Round Robin rules for your support team.

Heads up – this could take more than 30 minutes to complete.

Step 1: Create the following accounts/ files:

  • Zoho Desk (Free Edition)
  • Autocode (Free Edition) – we will use Autocode as an intermediary between WATI and Zoho
  • Get started with a Blank project
  • Make a copy of this Google Spreadsheet, in your google account.

Step 2: Create an app within Zoho Desk.

  • Go to Zoho API Console.
  • Click on ADD CLIENT.

    k0mlDQCDR8db6n5bmj8P X8cziz45z71Ju055F oO7e

  • Click on Self Client.
  • Enter Scope as Desk.tickets.ALL .
  • Select a limit of 10 minutes.
  • Type anything under Description.
  • Select your Production account.
  • Press Create.
  • From the pop-up that appears, copy the code.

You have now created a Zoho App, and you have the following details:

  • Code
  • Client ID
  • Client Secret

Step 3: Go to this Postman link.

  • Under Collections, click on Get tokens, and select the post request below.
  • In the window (on the right), select Params, and fill in the details that you received in Step 2.

    2g vf5cs5xqLtM53g JcDgBhdgsDutMO rSACEnLtirYR6GOhbM4e2Mhz3 F1fHzHeG HjvgaI6NNY6zJoW

  • Fill all 3 – client_id, client_secret and code.
  • Click on Send.

You will receive two tokens in the response – an authorization token and a refresh token.

  • Open up the Google Spreadsheet and save the tokens as follows:
  • Authorization token in cell H2, and refresh token in cell I2.

Step 4: Now, onto Autocode:

  • Gather data from Zoho Desk.
  • Organization ID: Settings > API > OrgId 
  • Department ID: Settings > Departments > Choose the Department
  • The ID is the number in the browser URL.

Open your Blank project on Autocode (sample window is added below).

  • Delete all the code that is present in the window.

    j7BntnvzWlQi3RFkbp7rYRryc4N3uq73Eve49VFbNirbO3DOu471NO

  • Copy and paste the code below (add necessary data gathered above).

				
					const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});



let ticketcheck = await lib.googlesheets.query['@0.3.0'].select({

 range: `A:F`, // required

 bounds: 'FIRST_EMPTY_ROW',

 where: [

   {

     'Phone__is': context.params.waId,

     'Status__is': "OPEN"

   }

   ],

 limit: { 

   'count': 0,

   'offset': 0

 }

});

console.log(ticketcheck)




if(ticketcheck.rows.length==0)

{

 let tokencheck = await lib.googlesheets.query['@0.3.0'].select({

   range: `H1:I2`, // required

   bounds: 'FIRST_EMPTY_ROW',

 });

 console.log(tokencheck)

  let token = tokencheck.rows[0].fields.Token

 console.log(token)

  if(tokencheck.rows[0].fields.Token=="")

 {

   let newtoken = await lib.http.request['@1.1.6']({

       method: 'POST',

       url: `https://accounts.zoho.in/oauth/v2/token`,

       queryParams:

       {

         'refresh_token':tokencheck.rows[0].fields.Refresh,

         'client_id': ``,

         'client_secret': ``,

         'grant_type':`refresh_token`

       }

   });

   console.log(newtoken)

  

   token = JSON.parse(newtoken.body.toString()).access_token

  

   let tokenreplace = await lib.googlesheets.query['@0.3.0'].update({

       range: `H1:H2`,

       bounds: 'FULL_RANGE',

       limit: {

         'count': 1,

         'offset': 0

       },

       fields: {

         'Token':token}

     });

   console.log(tokenreplace)

 }

    let zohoresult = await lib.http.request['@1.1.6'].post({

   url: `https://desk.zoho.in/api/v1/tickets`,

   headers: {

   "orgId": "",

   "authorization": "Zoho-oauthtoken "+token

   },

   params:

   {

     "departmentId":"",

     "subject": context.params.senderName+" "+context.params.waId,

     "contact":

     {

       "lastName":context.params.senderName

     }

   }

   });

  

   console.log(zohoresult)

   console.log(zohoresult.data.id)

    let newticket = await lib.googlesheets.query['@0.3.0'].insert({

   range: `A:F`,

   fieldsets: [

     {

       'Ticket': context.params.ticketId,

       'Created': context.params.created,

       'Phone': context.params.waId,

       'Sender': context.params.senderName,

       'Zoho Ticket': zohoresult.data.id,

       'Status': "OPEN"

     }

   ]

   });

   console.log(newticket)

}
				
			

After you do this, the window will prompt you to connect a resource. Now, connect your Google Spreadsheet created in Step 1.

Ensure you select the right sheet (within the spreadsheet).

adVcSvkcKONTjxrVzn0SGqxrojlbeWwRBtJNmR9U 54mT G0DRe7WjI 3VaFAEqTgdARdw2v mmz4pbZIPsJm3qwRDbtPur4hVHDNUfKo W9Cm24ecbA9zq3 DAML70Cp1A9IRP3

Save the code. This will create a URL at the bottom of your window. Copy this URL.

Step 5: Open your WATI Dashboard, and go to Webhooks. Now, add the URL from Step 4 as a new webhook.

Step 6: Open your Google Spreadsheet.

  • Go to Extensions > Apps Script.
  • Copy and paste this code under Code.gs 

 

				
					function myFunction() {

 var read = SpreadsheetApp.getActive().getSheetByName('Sheet1').getRange('H2').setValue("")

}
				
			

Now, create a trigger to run this code every 30 minutes, and that should be it.

If everything above went well, all your new chats will show up on Zoho Desk. 

But, you will still need to close tickets on both WATI and Zoho. There is a way to avoid this – we’ll share this in our next blog post.

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Leave a Comment

More To Explore