0

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.

furas
  • 134,197
  • 12
  • 106
  • 148
Josh D
  • 23
  • 5
  • this is not `Python` code but rather `JavaScript`. I remove tag `python` and add tag `javascript` – furas Aug 28 '22 at 19:22
  • maybe they change something on server - you may have to read documentation for `API`. Maybe in documentation you find also information about error codes `43`, `298` – furas Aug 28 '22 at 19:24
  • error suggest problem with JSON data and with text `"\n t..."`. Maybe it doesn't allow for `\n` or maybe text has to be shorter. – furas Aug 28 '22 at 19:30
  • `SendImage` sends `options` but `SendText` sends `payload`. Maybe it should also send `options` – furas Aug 28 '22 at 19:32

0 Answers0