Last active
December 3, 2020 11:57
-
-
Save whatsmate/588f9e98a9e1508bd7ce to your computer and use it in GitHub Desktop.
Sending a WhatsApp message in VB.NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.IO | |
Imports System.Net | |
Imports System.Text | |
Imports System.Web.Script.Serialization | |
Public Class WaMessageSender | |
''' TODO: Replace the following with your gateway instance ID, Forever Green client ID and secret below: | |
Private Const INSTANCE_ID As String = "YOUR_INSTANCE_ID_HERE" | |
Private Const CLIENT_ID As String = "YOUR_CLIENT_ID_HERE" | |
Private Const CLIENT_SECRET As String = "YOUR_CLIENT_SECRET_HERE" | |
Private Const API_URL As String = "http://api.whatsmate.net/v3/whatsapp/single/text/message/" + INSTANCE_ID | |
Public Function sendMessage(ByVal number As String, ByVal message As String) As Boolean | |
Dim success As Boolean = True | |
Dim webClient As New WebClient() | |
Try | |
Dim payloadObj As New Payload(number, message) | |
Dim serializer As New JavaScriptSerializer() | |
Dim postData As String = serializer.Serialize(payloadObj) | |
webClient.Headers("content-type") = "application/json" | |
webClient.Headers("X-WM-CLIENT-ID") = CLIENT_ID | |
webClient.Headers("X-WM-CLIENT-SECRET") = CLIENT_SECRET | |
webClient.Encoding = Encoding.UTF8 | |
Dim response As String = webClient.UploadString(API_URL, postData) | |
Console.WriteLine(response) | |
Catch webEx As WebException | |
Dim res As HttpWebResponse = DirectCast(webEx.Response, HttpWebResponse) | |
Dim stream As Stream = res.GetResponseStream() | |
Dim reader As New StreamReader(stream) | |
Dim body As String = reader.ReadToEnd() | |
Console.WriteLine(res.StatusCode) | |
Console.WriteLine(body) | |
success = False | |
End Try | |
Return success | |
End Function | |
Private Class Payload | |
Public number As String | |
Public message As String | |
Sub New(ByVal num As String, ByVal msg As String) | |
number = num | |
message = msg | |
End Sub | |
End Class | |
End Class | |
Module Module1 | |
Sub Main() | |
Dim waSender As New WaMessageSender() | |
waSender.sendMessage("12025550108", "Hey isn't it exciting?") ''' TODO: Specify the recipient's number here. NOT the gateway number | |
Console.WriteLine("Press Enter to exit") | |
Console.ReadLine() | |
End Sub | |
End Module |
Hi,
Please follow the steps as described on this page:
http://www.whatsmate.net/whatsapp-gateway-api.html
I want to test it for free...
How To Make INSTANCE_ID , CLIENT_ID , CLIENT_SECRET In Textbox ?
Private Const INSTANCE_ID As String = "YOUR_INSTANCE_ID_HERE"
Private Const CLIENT_ID As String = "YOUR_CLIENT_ID_HERE"
Private Const CLIENT_SECRET As String = "YOUR_CLIENT_SECRET_HERE"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
I used this code but No message received on WhatsApp.
Please Please help me
thank you in advance