whatsapp2
This commit is contained in:
@@ -755,6 +755,68 @@ Namespace Extensiones
|
|||||||
End Try
|
End Try
|
||||||
Return Retorno
|
Return Retorno
|
||||||
End Function
|
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
|
#End Region
|
||||||
|
|||||||
Reference in New Issue
Block a user