From 353c0bfcc1abb62cb6ed33008cbdeeb77b3ca3c5 Mon Sep 17 00:00:00 2001 From: rrene Date: Tue, 22 Oct 2024 16:00:59 -0700 Subject: [PATCH] whatsapp2 --- App_Code/modExtensiones.vb | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/App_Code/modExtensiones.vb b/App_Code/modExtensiones.vb index 5164ca1f2..148701a92 100644 --- a/App_Code/modExtensiones.vb +++ b/App_Code/modExtensiones.vb @@ -755,6 +755,68 @@ Namespace Extensiones End Try Return Retorno End Function + Public Function EnviarNotificacionWhatsApp2(NumeroTelefono As String, NombreUsuario As String, Mensaje As String) As Boolean + Dim RetornoObj As String = "{}" + Dim Retorno As Boolean = False + + Try + Dim TokenAutorizacion As String = $"Bearer {WhatsAppToken}" + Using httpClient = New HttpClient() + Using request = New HttpRequestMessage(HttpMethod.Post, New Uri("https://graph.facebook.com/v20.0/425866980604901/messages")) + + request.Headers.Add("Authorization", TokenAutorizacion) + Dim json = New Newtonsoft.Json.Linq.JObject() + json.Add(New Newtonsoft.Json.Linq.JProperty("messaging_product", "whatsapp")) + json.Add(New Newtonsoft.Json.Linq.JProperty("to", NumeroTelefono)) + + json.Add(New Newtonsoft.Json.Linq.JProperty("type", "template")) + + Dim plantilla As New Newtonsoft.Json.Linq.JObject( + New Newtonsoft.Json.Linq.JProperty("name", "textolibre"), + New Newtonsoft.Json.Linq.JProperty("language", + New Newtonsoft.Json.Linq.JObject( + New Newtonsoft.Json.Linq.JProperty("code", "es_MX") + ) + ), + New Newtonsoft.Json.Linq.JProperty("components", + New Newtonsoft.Json.Linq.JArray( + New Newtonsoft.Json.Linq.JObject( + New Newtonsoft.Json.Linq.JProperty("type", "body"), + New Newtonsoft.Json.Linq.JProperty("parameters", + New Newtonsoft.Json.Linq.JArray( + New Newtonsoft.Json.Linq.JObject( + New Newtonsoft.Json.Linq.JProperty("type", "text"), + New Newtonsoft.Json.Linq.JProperty("text", Mensaje) + ) + ) + ) + ) + ) + ) + ) + + + json.Add(New Newtonsoft.Json.Linq.JProperty("template", plantilla)) + + Using content = New StringContent(json.ToString, Encoding.UTF8, "application/json") + request.Content = content + Dim response = httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).Result + + If response.StatusCode = Net.HttpStatusCode.OK Then + RetornoObj = response.Content.ReadAsStringAsync().Result + Retorno = True + End If + End Using + + End Using + + End Using + Catch ex As Exception + RetornoObj = New Newtonsoft.Json.Linq.JObject(New Newtonsoft.Json.Linq.JProperty("Error", ex.ToString())).ToString() + GuardaLog("Ocurrió un error al enviar la informacion por whatsapp" & ex.Message) + End Try + Return Retorno + End Function #End Region