diff --git a/App_Code/modExtensiones.vb b/App_Code/modExtensiones.vb index 4599ce6a7..713016e1a 100644 --- a/App_Code/modExtensiones.vb +++ b/App_Code/modExtensiones.vb @@ -628,24 +628,38 @@ 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 + Public Function EnviarNotificacionWhatsApp(NumeroTelefono As String, Mensaje As String, Optional NombrePlantilla As String = "") As Boolean Dim RetornoObj As String = "{}" Dim Retorno As Boolean = False + Dim Str As String = My.Computer.FileSystem.ReadAllText($"c:\temp\WSToken.txt") + Try - Dim TokenAutorizacion As String = "Bearer EAAVcZB36KfEEBO0OlN5ZAUPhNAUZCsHuMbpeVrrxZCJZAacLgBMOXXXcyA6aLEbbANMjbeTuJbsZC4IAvsZBwEALCYqc7oZCrnHF67sc0RYMBru9R0YKBFhi8gFjZAhJgoCJauBdZA30R9YPXZA2ZByQZAKclRCL20VLu74HEtw3YKu1MiG1vEsZANWJZAHhcJCUANUs3zIMFvoC6dBoJgQsABEZAYYZD" + Dim TokenAutorizacion As String = $"Bearer {Str}" Using httpClient = New HttpClient() - Using request = New HttpRequestMessage(HttpMethod.Post, New Uri("https://graph.facebook.com/v20.0/263533173499868/messages")) + Using request = New HttpRequestMessage(HttpMethod.Post, New Uri("https://graph.facebook.com/v20.0/400260286507131/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)) + If NombrePlantilla <> "" Then + json.Add(New Newtonsoft.Json.Linq.JProperty("type", "template")) + Dim msgtexto As New Newtonsoft.Json.Linq.JObject( + New Newtonsoft.Json.Linq.JProperty("name", NombrePlantilla), + New Newtonsoft.Json.Linq.JProperty("language", + New Newtonsoft.Json.Linq.JObject( + New Newtonsoft.Json.Linq.JProperty("code", "en_US")) + ) + ) + json.Add(New Newtonsoft.Json.Linq.JProperty("template", msgtexto)) + Else + 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)) + End If Using content = New StringContent(json.ToString, Encoding.UTF8, "application/json") request.Content = content @@ -667,6 +681,8 @@ Namespace Extensiones Return Retorno End Function + + #End Region #Region "files dropzone"