1 parent
3a2205147c
commit
37da9aabe3
9 files changed
+660
-3
No files matched your search
@@ -23,6 +23,7 @@ import {
|
||||
MessageFileRequest,
|
||||
MessageForwardRequest,
|
||||
MessageImageRequest,
|
||||
MessageLinkCustomPreviewRequest,
|
||||
MessageLinkPreviewRequest,
|
||||
MessageLocationRequest,
|
||||
MessagePollRequest,
|
||||
@@ -95,6 +96,25 @@ export class ChattingController {
|
||||
return whatsapp.sendVideo(request);
|
||||
}
|
||||
|
||||
@Post('/send/link-custom-preview')
|
||||
@ApiOperation({
|
||||
summary: 'Send a text message with a CUSTOM link preview.',
|
||||
description:
|
||||
'You can use regular /api/sendText if you wanna send auto-generated link preview.',
|
||||
})
|
||||
@UsePipes(new WAHAValidationPipe())
|
||||
async sendLinkCustomPreview(
|
||||
@Body() request: MessageLinkCustomPreviewRequest,
|
||||
): Promise<any> {
|
||||
const whatsapp = await this.manager.getWorkingSession(request.session);
|
||||
if (!request.text.includes(request.preview.url)) {
|
||||
throw new Error(
|
||||
'"text" must include the URL provided in the "preview.url"',
|
||||
);
|
||||
}
|
||||
return whatsapp.sendLinkCustomPreview(request);
|
||||
}
|
||||
|
||||
@Post('/sendButtons')
|
||||
@ApiOperation({
|
||||
summary: 'Send buttons (interactive message)',
|
||||
|
||||
@@ -52,6 +52,7 @@ import {
|
||||
MessageFileRequest,
|
||||
MessageForwardRequest,
|
||||
MessageImageRequest,
|
||||
MessageLinkCustomPreviewRequest,
|
||||
MessageLinkPreviewRequest,
|
||||
MessageLocationRequest,
|
||||
MessagePollRequest,
|
||||
@@ -421,6 +422,12 @@ export abstract class WhatsappSession {
|
||||
throw new NotImplementedByEngineError();
|
||||
}
|
||||
|
||||
sendLinkCustomPreview(
|
||||
request: MessageLinkCustomPreviewRequest,
|
||||
): Promise<any> {
|
||||
throw new NotImplementedByEngineError();
|
||||
}
|
||||
|
||||
abstract forwardMessage(request: MessageForwardRequest): Promise<WAMessage>;
|
||||
|
||||
abstract sendImage(request: MessageImageRequest);
|
||||
|
||||
@@ -2535,6 +2535,142 @@ export namespace messages {
|
||||
return Media.deserialize(bytes);
|
||||
}
|
||||
}
|
||||
export class LinkPreview extends pb_1.Message {
|
||||
#one_of_decls: number[][] = [];
|
||||
constructor(data?: any[] | {
|
||||
url?: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
image?: Uint8Array;
|
||||
}) {
|
||||
super();
|
||||
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls);
|
||||
if (!Array.isArray(data) && typeof data == "object") {
|
||||
if ("url" in data && data.url != undefined) {
|
||||
this.url = data.url;
|
||||
}
|
||||
if ("title" in data && data.title != undefined) {
|
||||
this.title = data.title;
|
||||
}
|
||||
if ("description" in data && data.description != undefined) {
|
||||
this.description = data.description;
|
||||
}
|
||||
if ("image" in data && data.image != undefined) {
|
||||
this.image = data.image;
|
||||
}
|
||||
}
|
||||
}
|
||||
get url() {
|
||||
return pb_1.Message.getFieldWithDefault(this, 1, "") as string;
|
||||
}
|
||||
set url(value: string) {
|
||||
pb_1.Message.setField(this, 1, value);
|
||||
}
|
||||
get title() {
|
||||
return pb_1.Message.getFieldWithDefault(this, 2, "") as string;
|
||||
}
|
||||
set title(value: string) {
|
||||
pb_1.Message.setField(this, 2, value);
|
||||
}
|
||||
get description() {
|
||||
return pb_1.Message.getFieldWithDefault(this, 3, "") as string;
|
||||
}
|
||||
set description(value: string) {
|
||||
pb_1.Message.setField(this, 3, value);
|
||||
}
|
||||
get image() {
|
||||
return pb_1.Message.getFieldWithDefault(this, 4, new Uint8Array(0)) as Uint8Array;
|
||||
}
|
||||
set image(value: Uint8Array) {
|
||||
pb_1.Message.setField(this, 4, value);
|
||||
}
|
||||
static fromObject(data: {
|
||||
url?: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
image?: Uint8Array;
|
||||
}): LinkPreview {
|
||||
const message = new LinkPreview({});
|
||||
if (data.url != null) {
|
||||
message.url = data.url;
|
||||
}
|
||||
if (data.title != null) {
|
||||
message.title = data.title;
|
||||
}
|
||||
if (data.description != null) {
|
||||
message.description = data.description;
|
||||
}
|
||||
if (data.image != null) {
|
||||
message.image = data.image;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
toObject() {
|
||||
const data: {
|
||||
url?: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
image?: Uint8Array;
|
||||
} = {};
|
||||
if (this.url != null) {
|
||||
data.url = this.url;
|
||||
}
|
||||
if (this.title != null) {
|
||||
data.title = this.title;
|
||||
}
|
||||
if (this.description != null) {
|
||||
data.description = this.description;
|
||||
}
|
||||
if (this.image != null) {
|
||||
data.image = this.image;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
serialize(): Uint8Array;
|
||||
serialize(w: pb_1.BinaryWriter): void;
|
||||
serialize(w?: pb_1.BinaryWriter): Uint8Array | void {
|
||||
const writer = w || new pb_1.BinaryWriter();
|
||||
if (this.url.length)
|
||||
writer.writeString(1, this.url);
|
||||
if (this.title.length)
|
||||
writer.writeString(2, this.title);
|
||||
if (this.description.length)
|
||||
writer.writeString(3, this.description);
|
||||
if (this.image.length)
|
||||
writer.writeBytes(4, this.image);
|
||||
if (!w)
|
||||
return writer.getResultBuffer();
|
||||
}
|
||||
static deserialize(bytes: Uint8Array | pb_1.BinaryReader): LinkPreview {
|
||||
const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new LinkPreview();
|
||||
while (reader.nextField()) {
|
||||
if (reader.isEndGroup())
|
||||
break;
|
||||
switch (reader.getFieldNumber()) {
|
||||
case 1:
|
||||
message.url = reader.readString();
|
||||
break;
|
||||
case 2:
|
||||
message.title = reader.readString();
|
||||
break;
|
||||
case 3:
|
||||
message.description = reader.readString();
|
||||
break;
|
||||
case 4:
|
||||
message.image = reader.readBytes();
|
||||
break;
|
||||
default: reader.skipField();
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
serializeBinary(): Uint8Array {
|
||||
return this.serialize();
|
||||
}
|
||||
static deserializeBinary(bytes: Uint8Array): LinkPreview {
|
||||
return LinkPreview.deserialize(bytes);
|
||||
}
|
||||
}
|
||||
export class MessageRequest extends pb_1.Message {
|
||||
#one_of_decls: number[][] = [];
|
||||
constructor(data?: any[] | {
|
||||
@@ -2549,6 +2685,7 @@ export namespace messages {
|
||||
replyTo?: string;
|
||||
id?: string;
|
||||
participants?: string[];
|
||||
preview?: LinkPreview;
|
||||
}) {
|
||||
super();
|
||||
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [11], this.#one_of_decls);
|
||||
@@ -2586,6 +2723,9 @@ export namespace messages {
|
||||
if ("participants" in data && data.participants != undefined) {
|
||||
this.participants = data.participants;
|
||||
}
|
||||
if ("preview" in data && data.preview != undefined) {
|
||||
this.preview = data.preview;
|
||||
}
|
||||
}
|
||||
}
|
||||
get session() {
|
||||
@@ -2666,6 +2806,15 @@ export namespace messages {
|
||||
set participants(value: string[]) {
|
||||
pb_1.Message.setField(this, 11, value);
|
||||
}
|
||||
get preview() {
|
||||
return pb_1.Message.getWrapperField(this, LinkPreview, 12) as LinkPreview;
|
||||
}
|
||||
set preview(value: LinkPreview) {
|
||||
pb_1.Message.setWrapperField(this, 12, value);
|
||||
}
|
||||
get has_preview() {
|
||||
return pb_1.Message.getField(this, 12) != null;
|
||||
}
|
||||
static fromObject(data: {
|
||||
session?: ReturnType<typeof Session.prototype.toObject>;
|
||||
jid?: string;
|
||||
@@ -2678,6 +2827,7 @@ export namespace messages {
|
||||
replyTo?: string;
|
||||
id?: string;
|
||||
participants?: string[];
|
||||
preview?: ReturnType<typeof LinkPreview.prototype.toObject>;
|
||||
}): MessageRequest {
|
||||
const message = new MessageRequest({});
|
||||
if (data.session != null) {
|
||||
@@ -2713,6 +2863,9 @@ export namespace messages {
|
||||
if (data.participants != null) {
|
||||
message.participants = data.participants;
|
||||
}
|
||||
if (data.preview != null) {
|
||||
message.preview = LinkPreview.fromObject(data.preview);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
toObject() {
|
||||
@@ -2728,6 +2881,7 @@ export namespace messages {
|
||||
replyTo?: string;
|
||||
id?: string;
|
||||
participants?: string[];
|
||||
preview?: ReturnType<typeof LinkPreview.prototype.toObject>;
|
||||
} = {};
|
||||
if (this.session != null) {
|
||||
data.session = this.session.toObject();
|
||||
@@ -2762,6 +2916,9 @@ export namespace messages {
|
||||
if (this.participants != null) {
|
||||
data.participants = this.participants;
|
||||
}
|
||||
if (this.preview != null) {
|
||||
data.preview = this.preview.toObject();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
serialize(): Uint8Array;
|
||||
@@ -2790,6 +2947,8 @@ export namespace messages {
|
||||
writer.writeString(10, this.id);
|
||||
if (this.participants.length)
|
||||
writer.writeRepeatedString(11, this.participants);
|
||||
if (this.has_preview)
|
||||
writer.writeMessage(12, this.preview, () => this.preview.serialize(writer));
|
||||
if (!w)
|
||||
return writer.getResultBuffer();
|
||||
}
|
||||
@@ -2832,6 +2991,9 @@ export namespace messages {
|
||||
case 11:
|
||||
pb_1.Message.addToRepeatedField(message, 11, reader.readString());
|
||||
break;
|
||||
case 12:
|
||||
reader.readMessage(message.preview, () => message.preview = LinkPreview.deserialize(reader));
|
||||
break;
|
||||
default: reader.skipField();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ goog.exportSymbol('proto.messages.JidRequest', null, global);
|
||||
goog.exportSymbol('proto.messages.JidStringRequest', null, global);
|
||||
goog.exportSymbol('proto.messages.Json', null, global);
|
||||
goog.exportSymbol('proto.messages.JsonList', null, global);
|
||||
goog.exportSymbol('proto.messages.LinkPreview', null, global);
|
||||
goog.exportSymbol('proto.messages.LogLevel', null, global);
|
||||
goog.exportSymbol('proto.messages.MarkReadRequest', null, global);
|
||||
goog.exportSymbol('proto.messages.Media', null, global);
|
||||
@@ -662,6 +663,27 @@ if (goog.DEBUG && !COMPILED) {
|
||||
*/
|
||||
proto.messages.Media.displayName = 'proto.messages.Media';
|
||||
}
|
||||
/**
|
||||
* Generated by JsPbCodeGenerator.
|
||||
* @param {Array=} opt_data Optional initial data array, typically from a
|
||||
* server response, or constructed directly in Javascript. The array is used
|
||||
* in place and becomes part of the constructed object. It is not cloned.
|
||||
* If no data is provided, the constructed object will be empty, but still
|
||||
* valid.
|
||||
* @extends {jspb.Message}
|
||||
* @constructor
|
||||
*/
|
||||
proto.messages.LinkPreview = function(opt_data) {
|
||||
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
|
||||
};
|
||||
goog.inherits(proto.messages.LinkPreview, jspb.Message);
|
||||
if (goog.DEBUG && !COMPILED) {
|
||||
/**
|
||||
* @public
|
||||
* @override
|
||||
*/
|
||||
proto.messages.LinkPreview.displayName = 'proto.messages.LinkPreview';
|
||||
}
|
||||
/**
|
||||
* Generated by JsPbCodeGenerator.
|
||||
* @param {Array=} opt_data Optional initial data array, typically from a
|
||||
@@ -6338,6 +6360,250 @@ proto.messages.Media.prototype.setFilename = function(value) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (jspb.Message.GENERATE_TO_OBJECT) {
|
||||
/**
|
||||
* Creates an object representation of this proto.
|
||||
* Field names that are reserved in JavaScript and will be renamed to pb_name.
|
||||
* Optional fields that are not set will be set to undefined.
|
||||
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
|
||||
* For the list of reserved names please see:
|
||||
* net/proto2/compiler/js/internal/generator.cc#kKeyword.
|
||||
* @param {boolean=} opt_includeInstance Deprecated. whether to include the
|
||||
* JSPB instance for transitional soy proto support:
|
||||
* http://goto/soy-param-migration
|
||||
* @return {!Object}
|
||||
*/
|
||||
proto.messages.LinkPreview.prototype.toObject = function(opt_includeInstance) {
|
||||
return proto.messages.LinkPreview.toObject(opt_includeInstance, this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Static version of the {@see toObject} method.
|
||||
* @param {boolean|undefined} includeInstance Deprecated. Whether to include
|
||||
* the JSPB instance for transitional soy proto support:
|
||||
* http://goto/soy-param-migration
|
||||
* @param {!proto.messages.LinkPreview} msg The msg instance to transform.
|
||||
* @return {!Object}
|
||||
* @suppress {unusedLocalVariables} f is only used for nested messages
|
||||
*/
|
||||
proto.messages.LinkPreview.toObject = function(includeInstance, msg) {
|
||||
var f, obj = {
|
||||
url: jspb.Message.getFieldWithDefault(msg, 1, ""),
|
||||
title: jspb.Message.getFieldWithDefault(msg, 2, ""),
|
||||
description: jspb.Message.getFieldWithDefault(msg, 3, ""),
|
||||
image: msg.getImage_asB64()
|
||||
};
|
||||
|
||||
if (includeInstance) {
|
||||
obj.$jspbMessageInstance = msg;
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes binary data (in protobuf wire format).
|
||||
* @param {jspb.ByteSource} bytes The bytes to deserialize.
|
||||
* @return {!proto.messages.LinkPreview}
|
||||
*/
|
||||
proto.messages.LinkPreview.deserializeBinary = function(bytes) {
|
||||
var reader = new jspb.BinaryReader(bytes);
|
||||
var msg = new proto.messages.LinkPreview;
|
||||
return proto.messages.LinkPreview.deserializeBinaryFromReader(msg, reader);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes binary data (in protobuf wire format) from the
|
||||
* given reader into the given message object.
|
||||
* @param {!proto.messages.LinkPreview} msg The message object to deserialize into.
|
||||
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
|
||||
* @return {!proto.messages.LinkPreview}
|
||||
*/
|
||||
proto.messages.LinkPreview.deserializeBinaryFromReader = function(msg, reader) {
|
||||
while (reader.nextField()) {
|
||||
if (reader.isEndGroup()) {
|
||||
break;
|
||||
}
|
||||
var field = reader.getFieldNumber();
|
||||
switch (field) {
|
||||
case 1:
|
||||
var value = /** @type {string} */ (reader.readString());
|
||||
msg.setUrl(value);
|
||||
break;
|
||||
case 2:
|
||||
var value = /** @type {string} */ (reader.readString());
|
||||
msg.setTitle(value);
|
||||
break;
|
||||
case 3:
|
||||
var value = /** @type {string} */ (reader.readString());
|
||||
msg.setDescription(value);
|
||||
break;
|
||||
case 4:
|
||||
var value = /** @type {!Uint8Array} */ (reader.readBytes());
|
||||
msg.setImage(value);
|
||||
break;
|
||||
default:
|
||||
reader.skipField();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the message to binary data (in protobuf wire format).
|
||||
* @return {!Uint8Array}
|
||||
*/
|
||||
proto.messages.LinkPreview.prototype.serializeBinary = function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
proto.messages.LinkPreview.serializeBinaryToWriter(this, writer);
|
||||
return writer.getResultBuffer();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the given message to binary data (in protobuf wire
|
||||
* format), writing to the given BinaryWriter.
|
||||
* @param {!proto.messages.LinkPreview} message
|
||||
* @param {!jspb.BinaryWriter} writer
|
||||
* @suppress {unusedLocalVariables} f is only used for nested messages
|
||||
*/
|
||||
proto.messages.LinkPreview.serializeBinaryToWriter = function(message, writer) {
|
||||
var f = undefined;
|
||||
f = message.getUrl();
|
||||
if (f.length > 0) {
|
||||
writer.writeString(
|
||||
1,
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getTitle();
|
||||
if (f.length > 0) {
|
||||
writer.writeString(
|
||||
2,
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getDescription();
|
||||
if (f.length > 0) {
|
||||
writer.writeString(
|
||||
3,
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getImage_asU8();
|
||||
if (f.length > 0) {
|
||||
writer.writeBytes(
|
||||
4,
|
||||
f
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional string url = 1;
|
||||
* @return {string}
|
||||
*/
|
||||
proto.messages.LinkPreview.prototype.getUrl = function() {
|
||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @return {!proto.messages.LinkPreview} returns this
|
||||
*/
|
||||
proto.messages.LinkPreview.prototype.setUrl = function(value) {
|
||||
return jspb.Message.setProto3StringField(this, 1, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional string title = 2;
|
||||
* @return {string}
|
||||
*/
|
||||
proto.messages.LinkPreview.prototype.getTitle = function() {
|
||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, ""));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @return {!proto.messages.LinkPreview} returns this
|
||||
*/
|
||||
proto.messages.LinkPreview.prototype.setTitle = function(value) {
|
||||
return jspb.Message.setProto3StringField(this, 2, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional string description = 3;
|
||||
* @return {string}
|
||||
*/
|
||||
proto.messages.LinkPreview.prototype.getDescription = function() {
|
||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, ""));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @return {!proto.messages.LinkPreview} returns this
|
||||
*/
|
||||
proto.messages.LinkPreview.prototype.setDescription = function(value) {
|
||||
return jspb.Message.setProto3StringField(this, 3, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional bytes image = 4;
|
||||
* @return {!(string|Uint8Array)}
|
||||
*/
|
||||
proto.messages.LinkPreview.prototype.getImage = function() {
|
||||
return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 4, ""));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional bytes image = 4;
|
||||
* This is a type-conversion wrapper around `getImage()`
|
||||
* @return {string}
|
||||
*/
|
||||
proto.messages.LinkPreview.prototype.getImage_asB64 = function() {
|
||||
return /** @type {string} */ (jspb.Message.bytesAsB64(
|
||||
this.getImage()));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional bytes image = 4;
|
||||
* Note that Uint8Array is not supported on all browsers.
|
||||
* @see http://caniuse.com/Uint8Array
|
||||
* This is a type-conversion wrapper around `getImage()`
|
||||
* @return {!Uint8Array}
|
||||
*/
|
||||
proto.messages.LinkPreview.prototype.getImage_asU8 = function() {
|
||||
return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8(
|
||||
this.getImage()));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {!(string|Uint8Array)} value
|
||||
* @return {!proto.messages.LinkPreview} returns this
|
||||
*/
|
||||
proto.messages.LinkPreview.prototype.setImage = function(value) {
|
||||
return jspb.Message.setProto3BytesField(this, 4, value);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* List of repeated fields within this message type.
|
||||
* @private {!Array<number>}
|
||||
@@ -6386,7 +6652,8 @@ proto.messages.MessageRequest.toObject = function(includeInstance, msg) {
|
||||
linkpreviewhighquality: jspb.Message.getBooleanFieldWithDefault(msg, 8, false),
|
||||
replyto: jspb.Message.getFieldWithDefault(msg, 9, ""),
|
||||
id: jspb.Message.getFieldWithDefault(msg, 10, ""),
|
||||
participantsList: (f = jspb.Message.getRepeatedField(msg, 11)) == null ? undefined : f
|
||||
participantsList: (f = jspb.Message.getRepeatedField(msg, 11)) == null ? undefined : f,
|
||||
preview: (f = msg.getPreview()) && proto.messages.LinkPreview.toObject(includeInstance, f)
|
||||
};
|
||||
|
||||
if (includeInstance) {
|
||||
@@ -6471,6 +6738,11 @@ proto.messages.MessageRequest.deserializeBinaryFromReader = function(msg, reader
|
||||
var value = /** @type {string} */ (reader.readString());
|
||||
msg.addParticipants(value);
|
||||
break;
|
||||
case 12:
|
||||
var value = new proto.messages.LinkPreview;
|
||||
reader.readMessage(value,proto.messages.LinkPreview.deserializeBinaryFromReader);
|
||||
msg.setPreview(value);
|
||||
break;
|
||||
default:
|
||||
reader.skipField();
|
||||
break;
|
||||
@@ -6581,6 +6853,14 @@ proto.messages.MessageRequest.serializeBinaryToWriter = function(message, writer
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getPreview();
|
||||
if (f != null) {
|
||||
writer.writeMessage(
|
||||
12,
|
||||
f,
|
||||
proto.messages.LinkPreview.serializeBinaryToWriter
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -6877,6 +7157,43 @@ proto.messages.MessageRequest.prototype.clearParticipantsList = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional LinkPreview preview = 12;
|
||||
* @return {?proto.messages.LinkPreview}
|
||||
*/
|
||||
proto.messages.MessageRequest.prototype.getPreview = function() {
|
||||
return /** @type{?proto.messages.LinkPreview} */ (
|
||||
jspb.Message.getWrapperField(this, proto.messages.LinkPreview, 12));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {?proto.messages.LinkPreview|undefined} value
|
||||
* @return {!proto.messages.MessageRequest} returns this
|
||||
*/
|
||||
proto.messages.MessageRequest.prototype.setPreview = function(value) {
|
||||
return jspb.Message.setWrapperField(this, 12, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Clears the message field making it undefined.
|
||||
* @return {!proto.messages.MessageRequest} returns this
|
||||
*/
|
||||
proto.messages.MessageRequest.prototype.clearPreview = function() {
|
||||
return this.setPreview(undefined);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether this field is set.
|
||||
* @return {boolean}
|
||||
*/
|
||||
proto.messages.MessageRequest.prototype.hasPreview = function() {
|
||||
return jspb.Message.getField(this, 12) != null;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -63,10 +63,10 @@ import {
|
||||
ChatRequest,
|
||||
CheckNumberStatusQuery,
|
||||
EditMessageRequest,
|
||||
MessageButtonReply,
|
||||
MessageFileRequest,
|
||||
MessageForwardRequest,
|
||||
MessageImageRequest,
|
||||
MessageLinkCustomPreviewRequest,
|
||||
MessageLocationRequest,
|
||||
MessageReactionRequest,
|
||||
MessageReplyRequest,
|
||||
@@ -692,6 +692,12 @@ export class WhatsappSessionGoWSCore extends WhatsappSession {
|
||||
throw new AvailableInPlusVersion();
|
||||
}
|
||||
|
||||
sendLinkCustomPreview(
|
||||
request: MessageLinkCustomPreviewRequest,
|
||||
): Promise<any> {
|
||||
throw new AvailableInPlusVersion();
|
||||
}
|
||||
|
||||
reply(request: MessageReplyRequest) {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ import {
|
||||
MessageFileRequest,
|
||||
MessageForwardRequest,
|
||||
MessageImageRequest,
|
||||
MessageLinkCustomPreviewRequest,
|
||||
MessageLinkPreviewRequest,
|
||||
MessageLocationRequest,
|
||||
MessagePollRequest,
|
||||
@@ -824,6 +825,12 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
|
||||
throw new AvailableInPlusVersion();
|
||||
}
|
||||
|
||||
sendLinkCustomPreview(
|
||||
request: MessageLinkCustomPreviewRequest,
|
||||
): Promise<any> {
|
||||
throw new AvailableInPlusVersion();
|
||||
}
|
||||
|
||||
protected async uploadMedia(
|
||||
file: RemoteFile | BinaryFile,
|
||||
type,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import {
|
||||
registerDecorator,
|
||||
ValidationArguments,
|
||||
ValidationOptions,
|
||||
} from 'class-validator';
|
||||
|
||||
export function IsFileType(validationOptions?: ValidationOptions) {
|
||||
return function (object: any, propertyName: string) {
|
||||
registerDecorator({
|
||||
name: 'isFileType',
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: validationOptions,
|
||||
validator: {
|
||||
validate(value: any, _args: ValidationArguments) {
|
||||
return (
|
||||
value &&
|
||||
typeof value === 'object' &&
|
||||
(typeof value.data === 'string' || typeof value.url === 'string')
|
||||
);
|
||||
},
|
||||
defaultMessage() {
|
||||
return 'must contain either "data" or "url".';
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -4,8 +4,17 @@ import {
|
||||
ApiProperty,
|
||||
getSchemaPath,
|
||||
} from '@nestjs/swagger';
|
||||
import { IsFileType } from '@waha/nestjs/validation/IsFileType';
|
||||
import { GetChatMessagesQuery } from '@waha/structures/chats.dto';
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
import { plainToInstance, Transform, Type } from 'class-transformer';
|
||||
import {
|
||||
IsBoolean,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsUrl,
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
|
||||
import {
|
||||
SessionBaseRequest,
|
||||
@@ -14,6 +23,9 @@ import {
|
||||
} from './base.dto';
|
||||
import {
|
||||
BinaryFile,
|
||||
FileContent,
|
||||
FileType,
|
||||
FileURL,
|
||||
RemoteFile,
|
||||
VideoBinaryFile,
|
||||
VideoRemoteFile,
|
||||
@@ -162,6 +174,73 @@ export class MessageTextRequest extends ChatRequest {
|
||||
linkPreviewHighQuality?: boolean = false;
|
||||
}
|
||||
|
||||
@ApiExtraModels(FileURL, FileContent)
|
||||
export class LinkPreviewData {
|
||||
@IsNotEmpty()
|
||||
@IsUrl({
|
||||
protocols: ['http', 'https'],
|
||||
require_protocol: true,
|
||||
require_tld: false,
|
||||
})
|
||||
url: string = 'https://github.com/';
|
||||
|
||||
@IsString()
|
||||
title: string = 'Your Title';
|
||||
|
||||
@IsString()
|
||||
description: string = 'Check this out, amazing!';
|
||||
|
||||
@IsOptional()
|
||||
@ValidateNested()
|
||||
@Transform(
|
||||
({ value }) => {
|
||||
if (value?.url) {
|
||||
return plainToInstance(FileURL, value);
|
||||
}
|
||||
if (value?.data) {
|
||||
return plainToInstance(FileContent, value);
|
||||
}
|
||||
return value;
|
||||
},
|
||||
{ toClassOnly: true },
|
||||
)
|
||||
@IsFileType({ message: 'Image must contain either "data" or "url".' })
|
||||
@ApiProperty({
|
||||
oneOf: [
|
||||
{ $ref: getSchemaPath(FileURL) },
|
||||
{ $ref: getSchemaPath(FileContent) },
|
||||
],
|
||||
example: {
|
||||
url:
|
||||
process.env.WHATSAPP_SWAGGER_JPG_EXAMPLE_URL ||
|
||||
'https://github.com/devlikeapro/waha/raw/core/examples/waha.jpg',
|
||||
},
|
||||
})
|
||||
image?: FileType;
|
||||
}
|
||||
|
||||
export class MessageLinkCustomPreviewRequest extends ChatRequest {
|
||||
@IsString()
|
||||
@ApiProperty({
|
||||
description:
|
||||
'The text to send. MUST include the URL provided in preview.url',
|
||||
})
|
||||
text: string = 'Check this out! https://github.com/';
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
linkPreviewHighQuality?: boolean = true;
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => LinkPreviewData)
|
||||
preview: LinkPreviewData;
|
||||
|
||||
@ReplyToProperty()
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
reply_to?: string;
|
||||
}
|
||||
|
||||
export class EditMessageRequest {
|
||||
text: string = 'Hello, world!';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsBase64, IsNotEmpty, IsString, IsUrl } from 'class-validator';
|
||||
|
||||
export class Base64File {
|
||||
mimetype: string;
|
||||
@@ -117,3 +118,33 @@ export class VideoRemoteFile {
|
||||
})
|
||||
url: string;
|
||||
}
|
||||
|
||||
export class FileURL {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsUrl({
|
||||
protocols: ['http', 'https'],
|
||||
require_protocol: true,
|
||||
require_tld: false,
|
||||
})
|
||||
@ApiProperty({
|
||||
example:
|
||||
process.env.WHATSAPP_SWAGGER_JPG_EXAMPLE_URL ||
|
||||
'https://github.com/devlikeapro/waha/raw/core/examples/waha.jpg',
|
||||
})
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export class FileContent {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsBase64()
|
||||
@ApiProperty({
|
||||
description: 'Base64-encoded data of the file',
|
||||
example:
|
||||
'/9j/4AAQSkZJRgABAQAAAQABAAD//gAfQ29tcHJlc3NlZCBieSBqcGVnLXJlY29tcHJlc3P/2wCEAAQEBAQEBAQEBAQGBgUGBgg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Jzu9E82LTeaC7RcZTy7VGrxnYwPWPKr/AJrhoOHS0RWWq3E70j7ek4qKmermeeplaSVjtZviWnqZ6SZJ6aVo5F3MuMv5shuHFUldwY6ncp3I5+/q8nZlRWZiAoGpJxmLNjTF6K1uVj3PMN7dS9XX8U5cza0BSiurloT3qzHevU334RldVZWBUjUEeSSyx08TyzOFRQWZidAAMZizLLc2alpGZKMHsMnWerq+K8uZnltTrS1TF6Jj2mP7x1YhminjSWF1ZHAKlTqCPIp5o4InllcJGgJLHYABjMOYpbtK0EJKUanYu4uRzt8W5dzFNaJVhmYtRsdq86E86/aMQzRzxJNE4aNgGVgdQQfIHdY0Z3YKqjUk7ABjMuYnukrUtMxFGjfzCOc9XR8X5ZzG9pmFNUuTRufXGTzjqwjq6q6MCrDUEbQR4fNmYjUM9son/BKdJnHnkeaOofEmh36Yeppo/wAZUwp6UijBudtG+4U381cLX0D+LXU57JVwrK+1HVvRIPgco5ka
Line truncated
|
||||
})
|
||||
data?: string;
|
||||
}
|
||||
|
||||
export type FileType = FileURL | FileContent;
|
||||
Reference in new issue
Block a user