Question Details

Answered
Send image using Google Apps Script

Hi guys,

I've just started developing a bot that I will use with a Google Form and GAS. I have the bot working no problem with text however, now I may need to send a submitted picture also. I've search and searched and read and read but can't get a working solution. My current text code is:

 function sendLineNotify(message){
  var token = "f - - - - - 5"
  var options =
   {
     "method"  : "post",
     "payload" : "message="+message,
     "headers" : {"Authorization" : "Bearer " + token}
   };
   UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);
}

I've tried several different ways of trying to modify the payload to send an image with no success. I get a server errors 400 "the message can't be empty" or invalid request etc

function sendLineNotify(message) {

	var message =
		
		var token = "fP------U5"
		var options = {
		"method" : "post",
		"message=" : {
			"type" : "image",
			"originalContentUrl" : "https://lh3.ggpht.com/6jmzKXoPG4WCSvUWn8ZpFYb2HNO6oMwPoKH36BrGT_Mril1JrMkUs9cEBlyoc4gVNw=s128.jpg",
			"previewImageUrl" : "https://lh3.ggpht.com/6jmzKXoPG4WCSvUWn8ZpFYb2HNO6oMwPoKH36BrGT_Mril1JrMkUs9cEBlyoc4gVNw=s128.jpg",
			"animated" : false
		},
		"headers" : {
			"Authorization" : "Bearer " + token
		}
	};
	Logger.log(UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options));
}

Is it possible to send an image using GAS, I assume it is just my lack of knowledge is letting me down.

0
Edited: 1 years ago
Profile picture
James D ����

Answers

2
Profile picture
Aekawit
Posted: 6 months ago

https://moremeng.in.th/2019/02/send-message-to-line-notify-with-google-form-app-script.html

Profile picture
Chawan_Rchoo
Posted: 4 months ago

I've tried and took a long time Googling and played with your code...finally Bravo!! Try this Hope it Helps. .......................................................................................................................................... function sendImgLineNotify(){ var token = "BL.........UM"; var message = "Hello Guys What's Up!"; var imgThumbnail = "imgURL"; // Maximum size of 240×240px JPEG var imgFullsize = "imgURL"; //Maximum size of 1024×1024px JPEG var formData = { 'message' : message, 'imageThumbnail': imgThumbnail, 'imageFullsize' : imgFullsize, }
var options = { "method" : "post", "payload" : formData, "headers" : {"Authorization" : "Bearer " + token} }; UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options); }

** Ref : https://notify-bot.line.me/doc/en/

Are you sure? question.vm