Reputation: 23
Good morning.
My group has a GroupMe bot, which was coded long before I joined the group. It stopped sending text responses, but continues to send image & video responses.
The code for the bot runs as a Google script & is as follows:
function sendText(text){
if (text.length > 999) {
text = text.substring(0,995) + "...";
}
var payload = {
"bot_id" : botId,
"text" : text
};
var options = {
"method" : "post",
"payload" : JSON.stringify(payload)
};
UrlFetchApp.fetch("https://api.groupme.com/v3/bots/post", payload);
}
function sendImage(caption, url) {
var payload = {
"bot_id" : botId,
"text" : caption,
"attachments" : [
{
"type" : "image",
"url" : url
}
]
};
var options = {
"method" : "post",
"payload" : JSON.stringify(payload)
};
UrlFetchApp.fetch("https://api.groupme.com/v3/bots/post", options);
}
#more code
function doPost(e){
var post = JSON.parse(e.postData.getDataAsString());
var text = post.text;
var name = post.name;
var id = post.id;
var sender_id = post.sender_id;
var user_id = post.user_id;
var group_id = post.group_id;
var attachments = post.attachments;
if (group_id == mainGroupID) {
botId = mainBotID;
botName = mainBotName;
}
if(text.toLowerCase().substring(0, 3) == "!hi"){
sendText("Hello, " + name);
}
if (messageHasCommandInOurList) {
sendImage(commandList.values[x][2].toString(),commandList.values[x][3].toString());
}
This is the error response when we try to SendText():
Request failed for https: //api.groupme.com returned code 400. Truncated server response: {"meta":{"code":400,"errors":["Client submitted invalid JSON: lexical error: invalid string in json text.\n t... (use muteHttpExceptions option to examine full response)
at .sendText ( Code:43 )
at .doPost ( Code:298 )
We do not have logging set up, only error reporting, so I can't see why Images are sending successfully while Text isn't.
Upvotes: 0
Views: 74