From 688358b10b5b3ece4e2137c62f4034a4a7703267 Mon Sep 17 00:00:00 2001 From: rrene Date: Sat, 13 Jul 2024 08:46:21 -0700 Subject: [PATCH] =?UTF-8?q?--activaci=C3=B3n=20envio=20whatsapp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App_Code/modExtensiones.vb | 43 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/App_Code/modExtensiones.vb b/App_Code/modExtensiones.vb index 5bb948f6b..0785bc7fe 100644 --- a/App_Code/modExtensiones.vb +++ b/App_Code/modExtensiones.vb @@ -450,8 +450,8 @@ Namespace Extensiones ToastInformacion = 5 'succes ToastInformacionB = 6 'info ToastError = 7 'error - ToastAdventencia = 8 'Warning - + ToastAdventencia = 8 'Warning + End Enum Public Sub Alert(Obj As Object, Mensaje As String, pOpcion As TipoMensaje, Optional JSBtnAceptar As String = "", Optional TextoConfirmacion As String = "Aceptar", Optional TextoCancelacion As String = "Cancelar", Optional TimeoutToast As Integer = 5, Optional ShowCloseButton As Boolean = True, Optional TextoSegundoBoton As String = "", Optional JSBtn2 As String = "") @@ -619,6 +619,45 @@ Namespace Extensiones Return String.Format("
  • {0}{3}
  • ", Time, Tipo, Ico, Mensaje, Link, If(tonewpage, "target=""_blank""", "")) End Function + Public Function EnviarNotificacionWhatsApp(NumeroTelefono As String, Mensaje As String) As Boolean + Dim RetornoObj As String = "{}" + Dim Retorno As Boolean = False + Try + Dim TokenAutorizacion As String = "Bearer EAAVcZB36KfEEBO0OlN5ZAUPhNAUZCsHuMbpeVrrxZCJZAacLgBMOXXXcyA6aLEbbANMjbeTuJbsZC4IAvsZBwEALCYqc7oZCrnHF67sc0RYMBru9R0YKBFhi8gFjZAhJgoCJauBdZA30R9YPXZA2ZByQZAKclRCL20VLu74HEtw3YKu1MiG1vEsZANWJZAHhcJCUANUs3zIMFvoC6dBoJgQsABEZAYYZD" + Using httpClient = New HttpClient() + Using request = New HttpRequestMessage(HttpMethod.Post, New Uri("https://graph.facebook.com/v20.0/263533173499868/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", "text")) + Dim msgtexto As New Newtonsoft.Json.Linq.JObject( + New Newtonsoft.Json.Linq.JProperty("preview_url", "true"), + New Newtonsoft.Json.Linq.JProperty("body", Mensaje.Replace("
    ", "\n")) + ) + json.Add(New Newtonsoft.Json.Linq.JProperty("text", msgtexto)) + + 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 #Region "files dropzone"