I'm trying to send a template message in C# using the WhatsApp Cloud API, I succeeded to send message when I used a template without any parameter:
{
"messaging_product": "whatsapp",
"to": "{{Recipient-Phone-Number}}",
"type": "template",
"template": {
"name": "hello_world",
"language": {
"code": "en_US"
}
}
}
To C# (Working)
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri(".0/596008323xxxxxx/messages"),
Headers =
{
{ "Authorization" , access_token}
},
Content = JsonContent.Create(new
{
messaging_product = "whatsapp",
to = "21xxxxxx",
type = "template",
template = new
{
name = "hello_world",
language = new {code = "en_US"}
}
})
};
But in another Whatsapp
template I used two parameters, So I failed to apply the parameters in C# code
This is working API
{
"messaging_product": "whatsapp",
"to": "{{Recipient-Phone-Number}}",
"type": "template",
"template": {
"name": "new_template",
"language": {
"code": "en_US"
},
"components": [
{
"type": "body",
"parameters": [
{"type": "text", "text":"person_name"},
{"type": "text", "text":"15"}
]
}]
}
}
Not Wotrking
C#
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri(".0/596008323xxxxxx/messages"),
Headers =
{
{ "Authorization" , access_token}
},
Content = JsonContent.Create(new
{
messaging_product = "whatsapp",
to = "21xxxxxx",
type = "template",
template = new
{
name = "new_template",
language = new {code = "en_US"},
components = new
{
type = "body",
parameters = new
{
text = "person_name",
text2= "15"
}
}
}
})
};
I have an error in appling parameters in C#, Any help with this?