0

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.