whatsapp icon indicating copy to clipboard operation
whatsapp copied to clipboard

No language flexibility

Open YazanFarrah opened this issue 2 years ago • 4 comments
trafficstars

Hello I noticed while using the package that it forces us to use only english_US templates, and if fixed to allow the users choose their template language code would be the most reasoning update so far since the package does the work and is efficient.

Map data = { "messaging_product": "whatsapp", "to": to, "type": "template", "template": { "name": templateName, "language": {"code": "en_US"} } };

YazanFarrah avatar Nov 15 '23 09:11 YazanFarrah

Assalamu Alaikum Yazan, do you mean that you can't send messages in any language except English, for example: you can't send messages in arabic with this package? Because I am trying to send messages using this package but the messages still doesn't show up? Thanks.

ibrahimgamalf avatar Nov 15 '23 18:11 ibrahimgamalf

W aalaykom al salam Ibrahim, well you'll notice here in the below image in my meta developer account, I have created few templates, using different language codes, such as ar which stands for Arabic, en_US => English(US), as well as en=>English image

What I noticed is that the package forces the users when sending a Template to use only en_US code for language, which isn't flexible in my opinion, so I modified the function and created my own function instead of using the package to send the template in my language that I wish to send in,

` Map<String, String>? _headers = { "Content-Type": "application/json", "Authorization": "Bearer ${dotenv.env['ACCESS_TOKEN']}" }; Future customMessagesTemplate({ required int? to, required String? templateName, required langCode, }) async { try { var url = 'https://graph.facebook.com/v14.0/${dotenv.env['PHONE_ID']}/messages'; Uri uri = Uri.parse(url);

Map data = {
  "messaging_product": "whatsapp",
  "to": to,
  "type": "template",
  "template": {
    "name": templateName,
    "language": {"code": langCode}
  }
};

var body = json.encode(data);

var response = await http.post(uri, headers: _headers, body: body);
if (response.statusCode == 200) {
  return json.decode(response.body);
} else {
  throw Exception(
      'Failed to send message: ${response.statusCode}, ${response.body}');
}

} catch (e) { throw Exception('Failed to send message'); } } `

using this function which is pretty easy to create instead of having to use the package currently since it forces the users to use en_US code only, makes it pretty flexible for anyone to send a template message based on their requirements (language wise) Hope this helped you, and don't hesitate in reaching out to me again! Happy coding.

YazanFarrah avatar Nov 15 '23 21:11 YazanFarrah

Assalamu Alaikum Yazan, jazakallah khairan for this explanation, sorry for responding late, it seems like it's a good solution, but I don't understand it well because I still new to flutter, I started learning flutter almost 6 months ago. If I use these lines of codes in my app, will it work, or is their any additional steps or packages, you said it's easy to create this function instead of using this package, I know that might take some time from you to explain to me but it's okay if you don't have time to respond to this message, I will try to understand how to use it, Thank you Yazan.

ibrahimgamalf avatar Nov 16 '23 18:11 ibrahimgamalf

Assalamu Alaikum Yazan, Thank you for writing this function, I was able to use it to send whatsapp messages, I only have one question if you don't mind. How I can send to multiple whatsapp numbers at the same time? I really appreciate your help.

ibrahimgamalf avatar Nov 25 '23 14:11 ibrahimgamalf

Sorry for the delay, we have released new version. now you can have language flexibility. please find more details here : https://whatsapp-flutter.github.io/docs/methods/messages/send-a-template

Please let me know, if you need any support.

rohit-chouhan avatar Jul 24 '24 13:07 rohit-chouhan