make a c++ code to send data to a telegram webhook purely in stdlib
- User
make a c++ code to send data to a telegram webhook purely in stdlib
Assistant
#include <iostream> #include <string> #include <curl/curl.h> using namespace std; int main() { // Initialize the CURL library curl_global_init(CURL_GLOBAL_ALL); // Set up the request URL string url = "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/sendMessage"; // Set up the request parameters string data = "chat_id=<YOUR_CHAT_ID>&text=<YOUR_MESSAGE>"; // Create a new CURL handle CURL *curl = curl_easy_init(); // Set the URL to send the request to curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); // Set the request method to POST curl_easy_setopt(curl, CURLOPT_POST, 1); // Set the request data curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); // Perform the request CURLcode res = curl_easy_perform(curl); // Check for errors if (res != CURLE_OK) { cout << "Error sending message: " << curl_easy_strerror(res) << endl; return 1; } // Clean up the CURL handle curl_easy_cleanup(curl); // Shutdown the CURL library curl_global_cleanup(); return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.