How to receive WhatsApp message in AppSheet

You can receive WhatsApp messages in your AppSheet App using webhooks. This solution consist on having a Table created in your AppSheet Database and then the webhook will call to your AppSheet and ask to add a row in your table with the text receive every time that a message is received in your whatsapp. If you want to know how to send WhatsApp messaged from AppSheet, please look at this post.

Step-by-step instructions on how to do it:

0) You need to have your APIKey in API v13 or above.

You can check your API version in the status page: https://api.textmebot.com/status.php?apikey=YOUR_APIKEY

If you are having an earlier version (<13), please contact support@textmebot.com to update your API version.

1) Got to your App in AppSheet and if you don’t have a Database, create one. If you already have a database created, go to step2.

2) Create a new table and name it “whatsapp” with the following Rows:

  • type (Text type)
  • from (Text type)
  • from_name (Text type)
  • to (Text Type)
  • file (Text Type)
  • message (Text Type)

Example:

3) Get the AppID and Enable the Integrations on your App. You will use the AppID in step 7).

Go to Settings, Integrations and get the App ID. Then Enable The Integrations.


4) Click Save!

5) Create an Application Access Key.

6) Get the Application Access Key. You will use it in step 7)

7) Build the AppSheet Webhook URL using the AppID (from step 3) and the Application Access Key (from step 6)

AppSheet Webhook:

https://api.appsheet.com/api/v2/apps/YOUR_APP_ID/tables/whatsapp/action?applicationAccessKey=YOUR_APP_ACCESS_KEY

Where YOUR_APP_ID is your AppID and YOUR_APP_ACCESS_KEY is your Application Access Key

For Example:
https://api.appsheet.com/api/v2/apps/0eb2c559-c8bf-4e51-9ac6-8421b921efb7/tables/whatsapp/action?applicationAccessKey=V2-hHxUb-iyPsS-u4Uyf-heJUc-Nj7LV-GLuel

8) Add the AppSheet webhook created on the previous step in TextMeBot Webhook for your APIkey using the URL: 

https://api.textmebot.com/webhook.php?apikey=YOUR_APIKEY

Where YOUR_APIKEY is your TextMeBot APIkey that is registered with your phone number.

Then

That’s it

9) All the messages received in your whatsapp will be added into the “whatsapp” table. You can trigger events every time that a new row is added.

Example:

Message Received in WhatsApp:
:

Messages sent to AppSheet via Webhook and then added into the Table:

How to receive images/PDF/Audio in AppSheet DB

You can received files (images/PDF,Audio) from WhatsApp into your AppSheet Database. You just need to send an email to support@textmebot.com asking to enable the reception of files into your webhook (it is already included in the Subscription Plan).
Once the receiption of files is enabled in your webhook, all the files received in your whatsapp will be saved in AWS S3 and the URL to download the files will be set in the DB entry.
Then you can access the URL to display or download the files.


Troubleshooting

If you are having problems to get the messages into your Worksheet, please try to call to the AppSheet Webhook manually in order to check the error message received.
You can use https://reqbin.com/ online tool to perform the POST request using your AppSheet Webhook URL.


1- Use the AppSheet Webhook URL created in Step 7.

2- Select POST
3- Select JSON as body type
4- Use the JSON payload below:

{"Action":"Add",
 "Properties":{
   "Locale":"en-US",
   "Timezone": "Arabian Standard Time"
 },
 "Rows":[
   {
     "type":"text",
     "from":"549341849231",
     "from_name":"David",
     "to":"549122124032",
     "file":"null",
     "message":"Hello AppSheet!"}
    ]
   } 

5- Click Send!
6- You will see if there is any error looking at the Status and Result received:

Example1:

Error: {"type":"https://tools.ietf.org/html/rfc7231#section-6.5.3","title":"Forbidden","status":403,"detail":"REST API invoke request failed: The ApplicationAccessKey in the HTTP header did not match any of the valid ApplicationAccessKeys for the called application.","traceId":"00-4f116b159efb59a1d5d4ee5c2bb7eda8-75cf09ac97c880f9-00"}

403 Error means that there is an authentication problem. Probably the AppID or Access Key are wrong.

Example2:

Error: {"type":"https://tools.ietf.org/html/rfc7231#section-6.6.1","title":"An error occurred while processing your request.","status":500,"detail":"REST API invoke request failed: Internal error: AppTemplate not found.","traceId":"00-5bf38b146b48b0e7cdd706cb10806346-fe307b9e1794d341-00"}

500 Error means that there is something wrong with the AppSheet like the table not found, field not found or AppID incorrect.

Example3:

If the row is added succssfully, it should return the Row ID together with some additional details.

Reference Material

Googlee AppSheet documentation is available here: 

https://support.google.com/appsheet/answer/10105398?hl=en&ref_topic=10105767&sjid=7167390905711204880-EU 

https://support.google.com/appsheet/answer/11628886?hl=en