WhatsApp Automation
Tags: mulesofthackathon, rpa, sikulix
Published: 2020-11-21 19:28:19

# **Everyday is an API day: What is WhatsApp Automation?**

`*WhatsApp is a freeware owned by Facebook which allows users to send text messages and voice messages, make voice and video calls, and share images, documents, user locations, and other media. It can be used on Mobile phone, on PCs using WhatsApp Web or computer application. It's widely used among friends, family, and neighborhood/community groups.*`

My nephew Venkat and I are part of a family group on WhatsApp with more than 50 Birthdays and Anniversaries to wish family for in a year and it is easy to forget often given our busy lives. Hence the reason why we wanted to automate a couple of scenarios while also taking advantage this hackathon to learn something new.

* *Send Birthday or Anniversary wishes to the relatives part of the family group.*
* *Update profile picture upon uploading any day or occasion specific picture.*

#### We used 
* _**Windows BAT** Scripts_ 
* _**Windows Task Scheduler** tasks_
* _**SikuliX Python** Desktop Script_ 
* _**MuleSoft APIs, File & Email connectors, Java Component** to invoke **SikuliX Java** code, and **DataWeave** to select data_ 
* _**WhatsApp Application**_ on the computer connected to a cell phone.

#### High Level Flow:
![High Level Diagram](https://dev-to-uploads.s3.amazonaws.com/i/22at75dro8ke49sm63uj.PNG)

#### High level Logic:
* Read a CSV file with pre-configured data for sending wishes
* Look for profile picture to update, if any
* Send wishes and set the profile picture. 
* We used **MuleSoft's** _**file connector**_ to read the CSV file, _**DataWeave**_ to select data for processing, _**Java component**_ to invoke a static method with _**SikuliX Java API**_ code which does all the heavy lifting of the WhatsApp automation, and _**Email connector**_ to email the log file from the run.
* We also created _**Windows Batch Scripts**_, and _**Task Scheduler**_ tasks to automatically wake up computer at a certain time, perform the automation, and make the computer go back to sleep again after all activities are done.

#### RAML:
```
#%RAML 1.0
types:
  Automation-API-Input:
    description: Automation API input
    example:
      strict: true
      value:
        sikuli_home_folder: "C:\\sikulix"
        sikuli_images_sub_folder: sikuli_images
        system_default_pictures_folder: "C:\\Users\\<username>\\Pictures"
        whatsapp_desktop_exe: WhatsApp.exe
        input_csv_file_name: input_data.csv
        process_done_flag_file: whatsapp_update_done.txt
    properties:
      sikuli_home_folder:
        type: string
      sikuli_images_sub_folder:
        description: Sub-folder in sikuli_home_folder having images needed by Mule Java code
        type: string
      system_default_pictures_folder:
        description: Default pictures folder path on your machine
        type: string
      whatsapp_desktop_exe:
        description: WhatsApp computer application name.
        type: string
      input_csv_file_name:
        description: This is the file name of the CSV file containing the greetings data
        type: string
      process_done_flag_file:
        description: Name of the file that Mule creates after all processing is done
        type: string
title: WhatsApp Automation
baseUri: http://localhost:8081
description: WhatsApp Automation API
mediaType:
  - application/json
version: v1
protocols:
  - HTTP
/whatsapp:
  post:
    displayName: Automation API
    body:
      type: Automation-API-Input
    responses:
      "200":
        description: Success
        body:
          text/plain:
            description: Success Response
            example: "***** Run Date: 20201121 ***** No Data To Process"
            type: string
/whatsapp/healthcheck:
  get:
    displayName: HealthCheck API
    description: External code invokes this API to ensure Mule application is up for further processing
    responses:
      "200":
        description: Success Response
```

#### Links to code and other resources
* [GitHub Repository](https://github.com/srkomma/mule-hackathon-2020)

* **README** documents on GitHub have a high level flow, detailed instructions on how to setup, execute code, code logic, and some SikuliX resources.

 1. [Main README](https://github.com/srkomma/mule-hackathon-2020/blob/master/README.md)

 2. [Additional README](https://github.com/srkomma/mule-hackathon-2020/blob/master/Additional-README.docx)

#### Video on Setup
{% youtube TK-v-a2Phhc %}

#### Quick demo of the automation
{% youtube Zv620Y1FJ3s %}

### About us
**Sreeni Komma**, MCD, MCIA
_In-depth experience creating custom enterprise solutions and integrations as a technical enthusiast with a passion for software development, solution design, and enterprise application integration / APIs. Certification as a MuleSoft Developer and Integration Architect with experience in MuleSoft solution deployment and design for a wide array of organizations._
[LinkedIn](www.linkedin.com/in/sreenikomma)

**Venkatarami Konudula**, M.S. Computer Science @Virginia Tech

_Graduating soon and interested in pursuing job opportunities in Full Stack and/or MuleSoft Development._
[LinkedIn](https://www.linkedin.com/in/vkonudula/)