javascript - GramJS Api.messages.Report() return 400 OPTION_INVALID - Stack Overflow

I have a method reportMessage:async reportMessage(channelId: string, messageId: number, reason: Report

I have a method reportMessage:

async reportMessage(channelId: string, messageId: number, reason: ReportReason, comment?: string) {
    let reasonApi: Api.TypeReportReason;
    
    switch (reason) {
      case ReportReason.SPAM:
        reasonApi = new Api.InputReportReasonSpam();
        break;
      case ReportReason.VIOLENCE:
        reasonApi = new Api.InputReportReasonViolence();
        break;
      case ReportReason.PORNOGRAPHY:
        reasonApi = new Api.InputReportReasonPornography();
        break;
      case ReportReason.COPYRIGHT:
        reasonApi = new Api.InputReportReasonCopyright();
        break;
      case ReportReason.CHILD_ABUSE:
        reasonApi = new Api.InputReportReasonChildAbuse();
        break;
      case ReportReason.FAKE:
        reasonApi = new Api.InputReportReasonFake();
        break;
      case ReportReason.OTHER:
      default:
        reasonApi = new Api.InputReportReasonOther();
        break;
    }

    return this.handleCall(
      (client) =>
        client.invoke(
          new Api.messages.Report({
            peer: channelId,
            id: [messageId],
            option: reasonApi.getBytes(),
            message: comment || "",
          })
        ),
      { name: "reportMessage" }
    );
  }

When I try to call the method, telegram returns me an error: OPTION_INVALID

I'm not sure if I'm passing the correct value in the option field, but I can't find any information on what it should look like.

Based on the documentation I tried to provide reason field instead of option:

async reportMessage(channelId: string, messageId: number, reason: ReportReason, comment?: string) {
    let reasonApi: Api.TypeReportReason;
    
    switch (reason) {
      case ReportReason.SPAM:
        reasonApi = new Api.InputReportReasonSpam();
        break;
      case ReportReason.VIOLENCE:
        reasonApi = new Api.InputReportReasonViolence();
        break;
      case ReportReason.PORNOGRAPHY:
        reasonApi = new Api.InputReportReasonPornography();
        break;
      case ReportReason.COPYRIGHT:
        reasonApi = new Api.InputReportReasonCopyright();
        break;
      case ReportReason.CHILD_ABUSE:
        reasonApi = new Api.InputReportReasonChildAbuse();
        break;
      case ReportReason.FAKE:
        reasonApi = new Api.InputReportReasonFake();
        break;
      case ReportReason.OTHER:
      default:
        reasonApi = new Api.InputReportReasonOther();
        break;
    }

    return this.handleCall(
      (client) =>
        client.invoke(
          new Api.messages.Report({
            peer: channelId,
            id: [messageId],
            reason: reasonApi,
            message: comment || "",
          })
        ),
      { name: "reportMessage" }
    );
  }

But in this case I have an error:

I also tried to create Buffer manually but failed again

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744791517a4593943.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信