0

I want to make a bot that can restrict new user that join to the group, below is my code, but when I run this, it seemed that it is not working. I guess I misunderstood the way of how 'chatpermission' work, but can't find it.

Here is the 'restrict' method from telegram web: link (I had already set the telegram webhook to this google app script)

e={
  message={
    new_chat_member={
      language_code=zh-hans,
      is_bot=false,
      username=jinyulink34,
      first_name=Jinyulink,
      id=1.292889543E9
    },
    date=1.58726641E9,
    from={
      language_code=zh-hans,
      is_bot=false,
      username=Jinyulink,
      first_name=Jinyulinm,
      id=9.50729481E8
    },
    message_id=222.0,
    new_chat_participant={
      username=jinyulink34,
      first_name=Jinyulink,
      id=1.292889543E9,
      language_code=zh-hans,
      is_bot=false
    },
    new_chat_members=[
      Ljava.lang.Object;@6957c279,
      chat={
        type=supergroup,
        username=jinyulin,
        id=-1.001365615879E12,
        title=Test
      }
    },
    update_id=3995756.0
  }

function identificar(e){
  var message = e.message.text;
  if (e.message.new_chat_members){
      var ChatPermissions = {
      "can_send_messages":false,
      "can_send_media_messages":false,
      "can_send_other_messages":false,
      "can_add_web_page_previews":false,
      "can_send_polls":false,
      "can_change_info":false,
      "can_invite_users":false,
      "can_pin_messages":false
    }
      var userid=JSON.parse(e.message.from.id);/*logger.log(userid)->shows(950729481)*/
      var restrict = {
        "method": "restrictChatMember",
        "chat_id": String(e.message.chat.id),
        "user_id": userid,
        "permissions":JSON.stringify(ChatPermissions)
      }
      start(restrict);
    }
}
function start(payload) {
    var data = {
        "method": "post",
        "payload": payload
    }
    var returned = UrlFetchApp.fetch("https://api.telegram.org/bot-token/", data);
}

I'm getting the following error:

{"ok":false,"error_code":400,"description":"Bad Request: wrong user_id specified"}

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Jim
  • 33
  • 7

0 Answers0