#include <WiFi.h>
#include <HTTPClient.h>
#define SSID "Wokwi-GUEST"
#define SERVER_NAME "https://notify-api.line.me/api/notify"
#define TOKEN "fXHtvuzVC8kM5T7qayQcu7lPdTJk1hY9mYuja0ahk27"
void sendLineImageURL(const char* message, const char* imageUrl)
{
HTTPClient http;
http.begin(SERVER_NAME);
http.addHeader("Authorization", "Bearer " + String(TOKEN));
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String payload = "message="+String(message)+"&imageThumbnail"+String(imageUrl)+"&imageFullsize"+String(imageUrl);
int httpResponseCode = http.POST(payload);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
} else {
Serial.print("Error sending message. HTTP response code: ");
Serial.println(httpResponseCode);
}
http.end();
}
void sendLineSticker(const char* message, int pkgId, int stickerId) {
HTTPClient http;
http.begin(SERVER_NAME);
http.addHeader("Authorization", "Bearer " + String(TOKEN));
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String payload = "message=" + String(message) + "&stickerPackageId=" + String(pkgId) + "&stickerId=" + String(stickerId);
int httpResponseCode = http.POST(payload);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
} else {
Serial.print("Error sending message. HTTP response code: ");
Serial.println(httpResponseCode);
}
http.end();
}
void sendLineNotify(const char* message) {
HTTPClient http;
http.begin(SERVER_NAME);
http.addHeader("Authorization", "Bearer " + String(TOKEN));
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String payload = "message=" + String(message);
int httpResponseCode = http.POST(payload);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
} else {
Serial.print("Error sending message. HTTP response code: ");
Serial.println(httpResponseCode);
}
http.end();
}
void setup() {
Serial.begin(9600);
Serial.print("Connecting to WiFi");
WiFi.begin(SSID, "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
//sendLineNotify("Hello from Teeraphat!");
sendLineSticker("Sticker Test",1,1);
sendLineImageURL("Test Image","https://static.wikia.nocookie.net/chainsaw-man/images/1/1b/Pochita.PNG");
}
void loop() {
delay(100); // TODO: Build something amazing!
}