The Way Of Life
Google

Monday, November 20, 2023

Aplikasi untuk Mengirim Pesan WhatsApp Otomatis

Kali ini saya akan sharing tentang bagaimana cara untuk mengirim pesan WhatsApp secara otomatis menggunakan aplikasi yang kita buat sendiri. Ada banyak cara yang bisa anda temukan di internet. Artikel yang saya tulis ini adalah salah satu caranya dan sudah saya buktikan berhasil.

Langkah langkahnya antara lain :

  1. Proses pengambilan data. Pada proses ini ada beberapa cara, antara lain menggunakan koneksi ke database langsung atau menggunakan API ( Application Programming Interface). Cara yang terakhir ini biasanya dipergunakan jika kita mengakses sistem yang dibuat oleh orang/pihak lain.
  2. Proses pengolahan data. Pada proses ini data yang sudah diterima harus diolah dahulu. Misal dalam tema kali ini adalah pengiriman pesan. Maka data mentah yang berupa misal nama,  alamat dan nomor telepon, perlu ditambah kalimat pesan sesuai dengan kebutuhan yang diinginkan.
  3. Proses pengiriman pesan. Pengiriman pesan WA untuk broadcast khususnya saat ini dimungkinkan melalui API yang disediakan rekanan WhatsApp yang ada di indonesia. Untuk saat ini karena kebetulan saya menggunakan produk dari Maxchat. Bukan karena saya ingin mempromosikan maxchat.

IMPLEMENTASI

Karena kebetulan aplikasi yang saya buat adalah menarik data dari sistem pihak lain, maka saya menggunakan API yang telah disediakan oleh vendor. Aplikasi yang saya buat adalah aplikasi Notifikasi WA di sebuah sekolah internasional. Aplikasi ini mengirimkan data ke orang tua murid jika salah satu anaknya masuk ke klinik di sekolah karena sudah hal.

  1. Proses memanggil fungsi API ke Skyward ( Sistem Informasi Akademik yang digunakan sekolah tersebut) saya kebetulan menggunakan bahasa pemogramaman Microsoft Visual Basic. Sebenarnya dengan bahasa pemrograman apa saja juga memungkinkan asal ada fungsi HTPP Request. Proses ini biasanya memerlukan beberapa parameter yaitu, alamat URL, user, password dan token. Ada bisa membaca detail-nya di tulisan saya sebelumnya disini.
  2. Pengolahan data. Setelah data diterima aplikasi (biasanya dalam bentuk JSON ) melalui http request yaitu berupa field student id, student name, status orang tua ( Ayah, Ibu, Guardian, Lain-nya ), Nama Ayah, nomor HP Ayah, Nama Ibu nomor HP Ibu, Nama Guardian, Nomor HP Guardian, Kelas, Tanggal Transaksi, Alasan masuk klinik, treatment, comment, dsb.  Maka perlu ditambahkan pesan tambahan agar pesan enak dan layak dibaca oleh orang tua murid yang nantinya akan menerima pesan WA. Juga untuk penyimpanan data ke database (MySQL/MariaDB) untuk mencatat error log serta mengecek apakah pesan tersebut sudah dikirim atau belum sehingga tidak ada duplikasi pengiriman pesan WA. 
  3. Proses pengiriman data. Kebetulan saya menggunakan API WA dari Maxchat. Sebanarnya ada banyak vendor rekanan WA di Indonesia selain Maxchat. Hanya karena kebetulan saya menggunakan API dari Maxchat maka fitur fitur dari Maxchat yang akan saya bahas. Parameter yang akan diperoleh dari maxchat adalah url endopoint untuk API.

Jika anda sudah mendaftar di maxchat maka anda akan mendapatkan link URL dan authorization key, lalu dokumentasi API yang bisa anda explore. Contoh link ada di bawah ini.

URL : https://core.maxchat.id/ nama-perusahaan /api/messages?skipBusy=true

Authorization : passkey

Dokumentasi : https://core.maxchat.id/nama-perusahaan/docs

  

Contoh format pesan text yang dikirim dalam bentuk JSON:

 {

"to":"0810000000000",

"type":"text",

"text":"Dear, *Mr. xxxx*\n \nWe would like to inform you that *Your Son* has visited school clinic.\n \nDate: 00 Nov 2023\nTime: 07:48:32 am\nOffice Visit Reason(s): Runny Nose\nTreatment(s): Apply Vicks VapoRub\nDisposition(s): Return to Class\nExamined By: Nurse \nComment: \nNotes: \n \n \nThank You.\n School Name \nFor further information please contact the school admin at\nhttps://wa.me/628200000000\n*This is an automated message - do not reply*",

"useTyping": true

}

Di maxchat juga disediakan fitur untuk mengecek apakah sebuah nomor wa aktif atau tidak dengan URL API : https://core.maxchat.id/nama-perusahaan/api/check?phone=081000000000'


Dengan respon balik exists  : true (artinya nomornya Aktif)  / false (Nomornya tidak aktif)

Juga karena ini adalah sebuah sekolah, maka tidak setiap waktu aplikasi ini aktif, program akan mulai aktif jam 7.30 pagi dan non aktif atau "tidur" jam 17.00, pada jam 12.00 siang hanya untuk mengecek bahwa program ini masih aktif berjalan saja. Pesan WA biasanya dikirim ke admin untuk mengetahui program masih berjalan atau error karena banyak sebab.

Demikian gambaran jika anda ingin membuat aplikasi notifikasi WA menggunakan bahasa pemogroman apapun dan API WA dari vendor apapapun karena pada intinya prosesnya akan sama.

Semoga bermanfaat.

 

Software :

Microsoft Visual Basic 6.0

MySQL / MariaDB

WhatsApp

Operating System : Windows 10

API Data : Skyward

API WA : Maxchat

Related links:

API Call Using Visual Basic 6 (JSON Response)

How to Make WhatsApp Office Visit / Clinic Notification on Skyward


Labels: , , , ,

Sunday, April 09, 2023

How to Make WhatsApp Office Visit / Clinic Notification on Skyward


As we know, until this article has been released. On Skyward, we are unable to make notifications through WhatsApp. Like Office Visit / Clinic Notification, Skyward only has e-mail notification. And the good news is, today I will share, how to make Office Visit Notification through WhatsApp using Skyward API and WhatsApp API.

First, you have to download Qmlative SDK from Skyward. If you have not used the Qmlativ SDK Explorer, you can download it by going to the Partner Portal, navigating to Documentation, clicking on Qmlativ, choosing "C# SDK", then choosing "Download" and then clicking the "Click here to download" link.  Once you have downloaded and extracted the .zip file, open up the folder and find the "QmlativSDKExplorer.exe.config" file and replace the following values:

  1. BaseUrl : this should be the API Url that you are using to connect
  2. Key : this should be your client key
  3. Secret : this should be your client secret

Once you've done that save and close the config file, then run the QmlativSDKExplorer.exe file.  Once it launches, simply click "Explore", and you should see something like the following image.

In the box on the left, expand the "Health" node, then scroll down to the "NameOfficeVisit" node and expand it, then expand the "Fields" node, and select each of the fields that you would want to include in the response from that object (note: there may not be many from this object that you're actually interested in at this time).  Scroll a little further down to the "Relationships" node and expand that node, and you will see all the relationships available to the NameOfficeVisit object, such as "Name", expand the nodes that you are interested in pulling data from, and you will notice that they, too, have "Fields" and "Relationships" nodes under them.  Also note, the grayed out nodes are not unavailable, they are usually relationships that will tend to create cartesian products if they are used, so they are not recommended.

Or you can download my xml saved items setting here.

It’s important to save your selected item to generate query on Qmlativ SDK because Skyward have maybe a hundred or thousand fields on the database and connections for sure. From my experience, it is hard to remember the selected field and intuitively choose the correct field. that’s why saving your selected fields is really important.

Skyward Qmlative SDK Explorer

Choosing your selected field on the SDK Explorer.

  • Health
    • NameOfficeVisit
      • Fields
        • NameOfficeVisitID
        • CreatedTime
        • EntityID
        • NameID
      • Relationships
        • Name
          • Demographics.Name
            • Fields
              • FirstName
              • LastName
              • ...

After you have done with the selected field. You can scroll all the way back up to the "NameOfficeVisit" node, and select it (don't uncheck it), and you should see a "Preview Data" button on the right-side of the screen. When you click that "Preview Data" button you will notice that it will open a screen allowing you to preview the data, but it will also add an entry to the bottom panel of the original window with a GET request that you can copy (though it doesn't scroll to the right, so you will want to copy the line and the line below to make sure you get everything).

https://skyward.iscorp.com/yourbaseurlAPI/custom/1/Health/NameOfficeVisit/1/250?searchFields%5B0%5D=NameOfficeVisitID&searchFields%5B1%5D=CreatedTime&searchFields%B2%5D=EntityID&searchFields%5B3%5D=NameID&searchFields%5B4%5D=Name.FirstName&seachFields%5B5%5D=Name.LastName&searchFields%5B6%5D=Name.Student.PrimaryStudentFamily.PrimaryStudentGuardian.NameGuardian.PrimaryNamePhone.PhoneNumber

Using that information, you can then translate it into your POST request by copying the search fields over to your query fields for your POST.  The only thing I would recommend is taking off the "%5B" and "%5D" after the "searchField" as it is unnecessary. But if you still using that code, it will still work, but just makes your query unnecessarily longer.


Now, with postman you can test the link to query data.

API Call Testing - postman

Don't forget to filter the result, for example only today's office visit transaction. you must add some code on the body request like code below.

{

    "SearchSort": [

    {

        "FieldName": "CreatedTime",

        "DocumentationIsComplete": true,

        "Descending": false

    }],

    "SearchCondition": {

        "DateTimeSearchCondition": {

            "ConditionType": "Greater",

            "FieldName": "CreatedTime",

            "Value": "2023-03-29T00:00:00"

        }

    }

}


Then in my project, I’m using Visual Basic 6 to connect with WA API from the provider. The paramater that I’ve used are :

  1. API URL
  2. Authorization 

You can download my code about API Call Using Visual Basic 6 here

And here is the code for call WA API.

url = "https://demo.waapi.id/demo1/api/chats/6281000000000(yourdestinationwanumber)/messages?direct=false"

xmlhttp.Open "POST", url, False

message= "Dear, " + "*" + GridResult.TextMatrix(1, 10) + "*" + "\n"

message = message + " " + "\n"

message = message + "We would like to inform you that " + "*" + GridResult.TextMatrix(1, 3) + "*" + " has visited school clinic." + "\n"

message = message + " " + "\n"

message = message + "Office Visit Reason(s): " + GridResult.TextMatrix(1, 5) + "\n"

message = message + "Treatment(s): " + GridResult.TextMatrix(1, 6) + "\n"

message = message + "Disposition(s): " + GridResult.TextMatrix(1, 4) + "\n"

message = message + "Examined By: " + GridResult.TextMatrix(1, 7) + "\n"

message = message + "Comment: " + GridResult.TextMatrix(1, 8) + "\n"

message = message + " " + "\n"

message = message + " " + "\n"

message = message + "Thank You." + "\n"

message = message + "Your School Name"


'create the body of the POST

sentitybody = "{" + vbCrLf + """text""" & ":""" & message + """" + vbCrLf + "}"


xmlhttp.setRequestHeader "Authorization", "Bearer" & " " & "8jRuDTXCwqqeqwewqkbVdfsderwr"

xmlhttp.setRequestHeader "Content-Type", "application/json"

Visual Basic WhatsApp Clinic Notification

The Image below is the result of the WhatsApp Clinic Notification.


Clinic WhatsApp Notification


Software :

Microsoft Visual Basic 6.0

Postman

WhatsApp API

Skyward Qmlative SDK

Skyward

related links:

Aplikasi untuk Mengirim Pesan WhatsApp Otomatis

Labels: , , ,

Sunday, February 26, 2023

How to send an Image(base64) to an API with Visual Basic

If from my last article, I explained how to make an API Call using Visual Basic. Today I will explain how to send an image to an API with Visual Basic.

The common way to send an image to an API is by using base64 encoding. If you don’t know what is base64 encoding is, you can see it here first.

There are so many ways to encode images in base64 format. But in this article, I’m using Visual Basic 6.0 to encode the image.

Without further ado, let’s read the step below.

First You can download the example base64 VB class here.

With that source code, you can try to upload an image. But that base64 class that I’ve downloaded has a “bug” that causes an error when we send an image to an API.

Here’s why?






That class is generating Enter characters or Carriage Return/CR characters causing an error because base64 encoding results are “dirty”. We can use Ms. Word to see these characters

So, the solution is we should remove all CR characters with Replace function on VB6.

Replace(Bas64.Base64Buf, vbCrLf, "")

You can add this code below to my source code that you can download here.

Base64StringImage = """" & Replace(Bas64.Base64Buf, vbCrLf, "") & """"

sEntityBody = "{" + vbCrLf + """reference_id"":99," + vbCrLf

sEntityBody = sEntityBody & """photo_image""" & ":" & Base64StringImage & vbCrLf & "}"


Good luck and hope this will be useful.


Software :

Windows 10 Pro

Ms. Visual Basic 6.0


Labels: , ,

Saturday, February 11, 2023

API Call Using Visual Basic 6 (JSON Response)


Today. I’m gonna show you how to make API (Application Programming Interface) Call using Microsoft Visual Basic 6. And the first step that you have to do is install Visual Basic, I’m using Visual Basic 6 by the way.

First, you must create Visual Basic Project and then go to Project – References , Add Microsoft XML v6.0 and then click OK.


Make a Procedure let say GetRequest


Public Sub GetRequest

Dim xmlhttp As New MSXML2.XMLHTTP60

Dim url as String

Dim Response as String


‘set url


url  = https://api.yourwebsite.com

xmlhttp.Open “POST”, url, False


‘set header

xmlhttp.setRequestHeader "Host:", "api.your.api.url.destionation.com"

xmlhttp.setRequestHeader " Key:", "xyz"

xmlhttp.setRequestHeader " Token:", "$2a$10$ "

xmlhttp.setRequestHeader "Origin:", "http://web.com"

xmlhttp.setRequestHeader "Content-Type", "application/json"


‘set body

sEntityBody = "{" + vbCrLf + """reference_id"":999," + vbCrLf

sEntityBody = sEntityBody & """image""" & ":" & Base64StringImage & vbCrLf & "}"

xmlhttp.send " " + sEntityBody


‘if status 200 ( success )

If xmlhttp.status = "200" Then

    Response = xmlhttp.responseText

    Set xmlhttp = Nothing

When we receive a response from server than we must parse JSON with JSON Parser

    Set p = JSON.parse(Response)

JSON parser for Visual Basic you can download from here and add to Project Modules.

If we want to extract data from JSON we can user object pointer like below :

Text1.text = P.item(“data” .Item("province").Item("raw")

If we want to extract data from members of the item we can code like this below :

For I = 1 To p.Item("data").Item("member").Count()

p.Item("data").Item("member")(I).Item("name")

Next I

End if


Hope this article help you.

Download Source Code API Call VB 6 here 

Software :

Microsoft Visual basic 6.0

JSON Parser  Class Library

Operating System : 

Windows 10 Pro


related links :

Labels: , ,