BlogAll Blog Posts | Next Post | Previous Post
Wednesday, November 2, 2022
With the release of the new TMS FNC Websocket pack and the newest iteration of the TMS FNC Cloud Pack we now offer full fledged support for receiving and sending WhatsApp messages using the WhatsApp Business API. The TMS FNC Cloud Pack enables the user to send various messages to people. but to receive messages, the WhatsApp Business API requires the user to setup a webhook (and obviously, it isnt directly possible to setup a webhook for a native Delphi application).
Therefore we introduced the TMSFNCWhatsAppServer and the TMSFNCWhatsAppReceiver component. We can easily set-up a server and client without a whole lot of code, the heavy lifting is done by these components. In this blog we will do a quick walkthrough on how you can accomplish this.
First of all, we will need to host a server somewhere. This server will act as the mediator between our WhatsApp client and the WhatsApp Business API. To do this, we can create a project and drop the TTMSFNCWhatsAppServer component on the form. Simply link the necessary certificate files in the properties(RootCertificateFileFile, CertificateFile, CertificateFileKeyFile), Set the required Port number and if needed a Pathname and you're good to go. No code is needed for this. The component will forward all communication between the WhatsApp Business API and the client.
You can find more information on how to set up the server here.
The client application will need both the TTMSFNCWhatsAppReceiver and the TTMSFNCCloudWhatsApp component. The former will handle all incoming messages whilst the latter will handle the sending of messages.
Simply set the host, path and port number and set the active property on true or call connect. you can then subscribe on the OnWhatsAppMessageReceived to start handling the messages.
Provide the APIKey and set the Phone Number ID and subscribe to the OnSendSuccess event.
As we use 2 stand-alone components in conjunction, there is a bit of code required to fully integrate both in a full-fledged WhatsApp project. But, we at TMS Software, have done some of the heavy lifting for you and wrote a wrapper unit which contains some logic to make integrating the components a bit easier. this wrapper unit can be found in the TMS FNC Cloud pack demo folder in the WhatsApp with WebSocket Demo client project.
This wrapper unit has a TTMSFNCWhatsAppConversations class. This class contains all unique phone numbers and all messages that have been sent/received to this number.
After instantiating the object you can simple add a new conversation by using the following code.
When receiving/sending a new message you can then use the following code snippets to add these messages to this list.
This blog post has not received any comments yet.
All Blog Posts | Next Post | Previous Post