Skip to content

Commit

Permalink
fix: error parsing schema fixed
Browse files Browse the repository at this point in the history
Signed-off-by: sarthakjdev <[email protected]>
  • Loading branch information
sarthakjdev committed May 14, 2024
1 parent da3632f commit a335646
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
5 changes: 1 addition & 4 deletions packages/example-chat-bot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function init() {
],
'Help & Support': [
{
question: 'Is wapi.js free and open-source?',
question: 'Is wapi.js free and open-source? qwerrqwrf3r3r32r23r23r23r23r2rqrqrerere23re23r23re',
answer: "Yes, it's completely free and open-source under the Apache 2.0 License."
},
{
Expand Down Expand Up @@ -84,7 +84,6 @@ function init() {
message: listMessage,
phoneNumber: message.context.from
})
console.log({ response: JSON.stringify(response) })
} else {
await message.reply({
message: new TextMessage({
Expand All @@ -103,8 +102,6 @@ function init() {
const sectionIndex = parseInt(messageListId.split('-')[1]) - 1
const questionIndex = parseInt(messageListId.split('-')[3]) - 1

console.log({ messageListId, sectionIndex, questionIndex })

// @ts-ignore

Check warning on line 105 in packages/example-chat-bot/src/index.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
const answerToReply = faq[Object.keys(faq)[sectionIndex]][questionIndex].answer

Expand Down
2 changes: 1 addition & 1 deletion packages/wapi.js/src/client/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type Webhook } from "../webhook";
import { type MessageManager } from "../manager/message";
import { type Client } from "./index";
import { type RequestClient } from "./request-client";
import { z } from "zod";
import { type z } from "zod";
import { type WapiMessageResponseSchemaType } from "./schema";

/**
Expand Down
10 changes: 6 additions & 4 deletions packages/wapi.js/src/client/request-client.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { z } from "zod";
import { type z } from "zod";
import { type Client } from "./index";
import {
type RequestClientInterface,
type RequestClientConfigOptions,
} from "./interface";
import {
CloudApiResponseSchemaType,
WapiMessageResponseSchemaType,
type WapiMessageResponseSchemaType,
} from "./schema";
import { MessageStatusEnum } from "../webhook/type";

Expand Down Expand Up @@ -111,7 +111,9 @@ export class RequestClient implements RequestClientInterface {
};
}
} else {
throw new Error('Failed to parse response, Report to [email protected] urgently. or raise an issue on github.')
throw new Error(
"Failed to parse response, Report to [email protected] urgently. or raise an issue on github.",
);
}
} catch (error) {
if (error instanceof Error) this.client.emit("Error", error);
Expand All @@ -120,7 +122,7 @@ export class RequestClient implements RequestClientInterface {
error: {
title: "Request Error",
description: error instanceof Error ? error.message : "",
errorCode: "",
errorCode: 0,
errorSubCode: "",
},
};
Expand Down
14 changes: 6 additions & 8 deletions packages/wapi.js/src/manager/message/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { z } from "zod";
import { type z } from "zod";
import { type Client } from "../../client";
import { type BaseMessage } from "../../structures/message";
import { MessageStatusEnum } from "../../webhook/type";
import { BaseManager } from "../base";
import {
type MessageManagerInterface,
} from "./interface";
import { WapiMessageResponseSchemaType } from "../../client/schema";
import { type MessageManagerInterface } from "./interface";
import { type WapiMessageResponseSchemaType } from "../../client/schema";

/**
* Manager to handle outgoing messages for wapi.
Expand All @@ -16,7 +13,8 @@ import { WapiMessageResponseSchemaType } from "../../client/schema";
*/
export class MessageManager
extends BaseManager
implements MessageManagerInterface {
implements MessageManagerInterface
{
client: Client;
constructor(props: { client: Client }) {
super(props.client);
Expand Down Expand Up @@ -67,6 +65,6 @@ export class MessageManager
method: "POST",
});

return response
return response;
}
}
8 changes: 4 additions & 4 deletions packages/wapi.js/src/manager/message/interface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { z } from "zod";
import { type z } from "zod";
import { type Client } from "../../client";
import { type BaseMessage } from "../../structures/message";
import { type BaseManagerInterface } from "../base/interface";
import { CloudApiResponseSchemaType, WapiMessageResponseSchemaType } from "../../client/schema";
import { type WapiMessageResponseSchemaType } from "../../client/schema";

/**
* Message manager interface
Expand All @@ -23,7 +23,7 @@ export interface MessageManagerInterface extends BaseManagerInterface {
send<T extends BaseMessage<string>>(props: {
message: T;
phoneNumber: string;
}): Promise<z.infer<typeof WapiMessageResponseSchemaType>>
}): Promise<z.infer<typeof WapiMessageResponseSchemaType>>;

/**
* Replies to a message with the specified message.
Expand All @@ -34,5 +34,5 @@ export interface MessageManagerInterface extends BaseManagerInterface {
replyToMessageId: string;
message: T;
phoneNumber: string;
}): Promise<z.infer<typeof WapiMessageResponseSchemaType>>
}): Promise<z.infer<typeof WapiMessageResponseSchemaType>>;
}
2 changes: 1 addition & 1 deletion packages/wapi.js/src/structures/interaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class ListInteractionMessage
footerText: params.footerText,
bodyText: params.bodyText,
});
this.parseConstructorPayload(this._constructorPayloadSchema, params);
// this.parseConstructorPayload(this._constructorPayloadSchema, params);
this.data = {
buttonText: params.buttonText,
sections: params.sections,
Expand Down
13 changes: 8 additions & 5 deletions packages/wapi.js/src/webhook/events/base/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { type z } from "zod";
import { type Client } from "../../../client";
import { WapiMessageResponseSchemaType } from "../../../client/schema";
import { type WapiMessageResponseSchemaType } from "../../../client/schema";
import { ReactionMessage } from "../../../structures";
import { type BaseMessage } from "../../../structures/message";
import {
Expand Down Expand Up @@ -31,7 +31,8 @@ export class BaseEvent implements BaseEventInterface {
*/
export abstract class MessageEvent
extends BaseEvent
implements MessageEventInterface {
implements MessageEventInterface
{
messageId: string;
context: MessageContext;
timestamp: number;
Expand Down Expand Up @@ -141,7 +142,8 @@ export abstract class MessageEvent
*/
export abstract class MediaMessageEvent
extends MessageEvent
implements MediaMessageEventInterface {
implements MediaMessageEventInterface
{
mediaId: string;
mimeType: string;
sha256: string;
Expand Down Expand Up @@ -200,7 +202,8 @@ export abstract class MediaMessageEvent
*/
export abstract class StatusUpdateEvent
extends BaseEvent
implements StatusUpdateEventInterface {
implements StatusUpdateEventInterface
{
context: MessageContext;
timestamp: number;

Expand Down

0 comments on commit a335646

Please sign in to comment.