0% found this document useful (0 votes)
16 views2 pages

Api Wsap

This document is a Visual Basic .NET program that sends a WhatsApp message using the Facebook Graph API. It constructs a JSON object with message details including recipient information, template name, and parameters, and then makes an HTTP POST request to send the message. The program checks the response to confirm if the message was sent successfully or if there was an error.

Uploaded by

Jhon Lopez mora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Api Wsap

This document is a Visual Basic .NET program that sends a WhatsApp message using the Facebook Graph API. It constructs a JSON object with message details including recipient information, template name, and parameters, and then makes an HTTP POST request to send the message. The program checks the response to confirm if the message was sent successfully or if there was an error.

Uploaded by

Jhon Lopez mora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Imports System.Net.

Http
Imports System.Text
Imports Newtonsoft.Json.Linq

Module Module1
Sub Main()
Dim phoneId As String = "Tu_Id_Telefonico"
Dim token As String = "Tu_Token"

Dim client = New HttpClient()


client.DefaultRequestHeaders.Authorization = New
System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token)

System.Net.ServicePointManager.SecurityProtocol =
System.Net.SecurityProtocolType.Tls12

Dim json = New JObject()

json.Add("recipient_type", "individual")
json.Add("to", "Tu_Numero_Destino")
json.Add("type", "template")
json.Add("template", New JObject From {
{"name", "Tu_Nombre_De_Plantilla"},
{"language", New JObject From {
{"code", "Tu_Codifocacion_De_Lenguaje_De_Plantilla"}
}},
{"components", New JArray From {
New JObject From {
{"type", "header"},
{"parameters", New JArray From {
New JObject From {
{"type", "text"},
{"text", "Tu_Parametro_1"}
}
}}
},
New JObject From {
{"type", "body"},
{"parameters", New JArray From {
New JObject From {
{"type", "text"},
{"text", "Tu_Parametro_1"}
},
New JObject From {
{"type", "text"},
{"text", "Tu_Parametro_2"}
},
New JObject From {
{"type", "text"},
{"text", "Tu_Parametro_3"}
},
New JObject From {
{"type", "text"},
{"text", "Tu_Parametro_4"}
}
}}
}
}}
})

json.Add("messaging_product", "whatsapp")

Dim response = client.PostAsync("https://graph.facebook.com/v16.0/" &


phoneId & "/messages", New StringContent(json.ToString(), Encoding.UTF8,
"application/json")).Result

If response.IsSuccessStatusCode Then
Console.WriteLine("El mensaje se ha enviado correctamente.")
Console.ReadKey()
Else
Console.WriteLine("Se produjo un error al enviar el mensaje: " &
response.Content.ReadAsStringAsync().Result)
Console.ReadKey()
End If

End Sub
End Module

You might also like