简体   繁体   English

如何仅在 C# 中使用 WhatsApp API 发送 WhatsApp 消息(不应使用任何第三方 API 链接)

[英]how to send WhatsApp message using WhatsApp API only in C#(should not use any third-party API links)

How to send WhatsApp Message using WhatsApp API only (should not use any third-party API links Ex: Twilio API, WART Tool WhatsApp....)如何仅使用 WhatsApp API 发送 WhatsApp 消息(不应使用任何第三方 API 链接,例如:Twilio API,WART 工具 WhatsApp....)

I searched in google but I didn't find any solution for this can you please tell me is there any way to send WhatsApp Message without using any third-party API links)我在谷歌搜索但我没有找到任何解决方案你能告诉我有什么方法可以发送 WhatsApp 消息而不使用任何第三方 API 链接)

Sorry for my bad English.对不起,我的英语不好。

use this tool: https://curl.olsh.me/ and copy the code of the test-message you get on YourMeatapp -> WhatsApp -> First steps -> send test message.使用此工具: https://curl.olsh.me/并复制您在 YourMeatapp -> WhatsApp -> 第一步 -> 发送测试消息上获得的测试消息的代码。 result ie结果即

using (var httpClient = new HttpClient())
{
    using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://graph.facebook.com/v14.0/[Your telephoneNumberId]/messages"))
    {
        reques]"); 

        request.Content = new StringContent("{ \"messaging_product\": \"whatsapp\", \"to\": \"[NumberToSend]\", \"type\": \"template\", \"template\": { \"name\": \"hello_world\", \"language\": { \"code\": \"en_US\" } } }");
        request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); 

        var response = await httpClient.SendAsync(request);
    }
}

replace the content between [] with your values.用您的值替换 [] 之间的内容。

If you only want to send a text message change the line requst.Content =... to:如果您只想发送短信,请将 requst.Content =... 行更改为:

String whatsAppContent = "";
        whatsAppContent += "\"messaging_product\": \"whatsapp\",";
        whatsAppContent += " \"recipient_type\":\"individual\",";
        whatsAppContent += " \"to\": \"[NumberToSend]\",";
        whatsAppContent += " \"type\": \"text\",";
        whatsAppContent += " \"text\": {\"preview_url\": false,\"body\": \" " + "Your message"+ "\"}";

request.Content = new StringContent("{" + whatsAppContent + "}"); request.Content = new StringContent("{" + whatsAppContent + "}");

kind regards亲切的问候

Ottilie奥蒂莉

You can either use WhatsApp's Official APIs or npm packages like waeasyapi or similar to send messages.您可以使用WhatsApp 的官方 API或 npm 包(如waeasyapi或类似)来发送消息。

WhatsApp only allows official business numbers to send and receive messages using APIs. WhatsApp 只允许官方商业号码使用 API 发送和接收消息。 Either way, you'll have to pay to use APIs.无论哪种方式,您都必须付费才能使用 API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM