Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Node.js Web API Examples

Primary Categories

ABN AMRO
AWS Translate
Activix CRM
Adyen
Amazon MWS
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bitfinex v2 REST
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Hungary NAV Invoicing
IBM Text to Speech
Jira
MYOB
Magento

MercadoLibre
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
Rabobank
SOAP finkok.com
Shippo
Shopify
SimpleTexting
Square
Stripe
SugarCRM
Trello
Twilio
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
WhatsApp
WooCommerce
Xero
Yousign
_Miscellaneous_
eBay
effectconnect

 

 

 

(Node.js) WhatsApp - Send a Linked Media Message

Demonstrates how to send a media message where the media content is a link to an external URL. This example demonstrates sending an image (JPG) media message.

For more information, see https://developers.facebook.com/docs/whatsapp/api/messages/media

Install Chilkat for Node.js and Electron using npm at

Chilkat npm packages for Node.js

Chilkat npm packages for Electron

on Windows, Linux, MacOSX, and ARM

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node11-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node11-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node11-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node11-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node11-linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('@chilkat/ck-node11-macosx');
}

function chilkatExample() {

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    var http = new chilkat.Http();
    var success;

    // Implements the following CURL command:

    // curl -X POST https://example.com/v1/messages \
    //   -H "Authorization: Bearer your-auth-token" \
    //   -d '
    // {
    //     "recipient_type": "individual-or-group",
    //     "to": "whatsapp-id-or-group-id",
    //     "type": "image",
    //     "image": {
    //       "link": "http(s)://the-url",
    //       "provider": {
    //         "name" : "provider-name"
    //       },
    //     "caption": "your-image-caption"
    //   }
    // }'

    // Use the following online tool to generate HTTP code from a CURL command
    // Convert a cURL Command to HTTP Source Code

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "recipient_type": "individual-or-group",
    //   "to": "whatsapp-id-or-group-id",
    //   "type": "image",
    //   "image": {
    //     "link": "http(s)://the-url",
    //     "provider": {
    //       "name": "provider-name"
    //     },
    //     "caption": "your-image-caption"
    //   }
    // }

    var json = new chilkat.JsonObject();
    json.UpdateString("recipient_type","individual-or-group");
    json.UpdateString("to","whatsapp-id-or-group-id");
    json.UpdateString("type","image");
    json.UpdateString("image.link","http(s)://the-url");
    json.UpdateString("image.provider.name","provider-name");
    json.UpdateString("image.caption","your-image-caption");

    // Adds the "Authorization: Bearer your-auth-token" header.
    http.AuthToken = "your-auth-token";

    // resp: HttpResponse
    var resp = http.PostJson3("https://example.com/v1/messages","application/json",json);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    var sbResponseBody = new chilkat.StringBuilder();
    resp.GetBodySb(sbResponseBody);
    var jResp = new chilkat.JsonObject();
    jResp.LoadSb(sbResponseBody);
    jResp.EmitCompact = false;

    console.log("Response Body:");
    console.log(jResp.Emit());

    var respStatusCode = resp.StatusCode;
    console.log("Response Status Code = " + respStatusCode);
    if (respStatusCode >= 400) {
        console.log("Response Header:");
        console.log(resp.Header);
        console.log("Failed.");

        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "messages": [
    //     {
    //       "id": "gBEGkYiEB1VXAglK1ZEqA1YKPrU"
    //     }
    //   ]
    // }

    // Sample code for parsing the JSON response...
    // Use the following online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    var id;

    var i = 0;
    var count_i = jResp.SizeOfArray("messages");
    while (i < count_i) {
        jResp.I = i;
        id = jResp.StringOf("messages[i].id");
        i = i+1;
    }


}

chilkatExample();

 

© 2000-2020 Chilkat Software, Inc. All Rights Reserved.