mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-18 19:32:21 -06:00
feat: dify now identifies images
This commit is contained in:
@@ -670,11 +670,27 @@ export class DifyService {
|
||||
: msg?.message?.audioMessage
|
||||
? `audioMessage|${mediaId}`
|
||||
: undefined,
|
||||
imageMessage: msg?.message?.imageMessage ? `imageMessage|${mediaId}` : undefined,
|
||||
videoMessage: msg?.message?.videoMessage ? `videoMessage|${mediaId}` : undefined,
|
||||
documentMessage: msg?.message?.documentMessage ? `documentMessage|${mediaId}` : undefined,
|
||||
documentWithCaptionMessage: msg?.message?.auddocumentWithCaptionMessageioMessage
|
||||
? `documentWithCaptionMessage|${mediaId}`
|
||||
imageMessage: msg?.message?.imageMessage
|
||||
? `imageMessage|${mediaId}${
|
||||
msg?.message?.imageMessage?.caption ? `|${msg?.message?.imageMessage?.caption}` : ''
|
||||
}`
|
||||
: undefined,
|
||||
videoMessage: msg?.message?.videoMessage
|
||||
? `videoMessage|${mediaId}${
|
||||
msg?.message?.videoMessage?.caption ? `|${msg?.message?.videoMessage?.caption}` : ''
|
||||
}`
|
||||
: undefined,
|
||||
documentMessage: msg?.message?.documentMessage
|
||||
? `documentMessage|${mediaId}${
|
||||
msg?.message?.documentMessage?.caption ? `|${msg?.message?.documentMessage?.caption}` : ''
|
||||
}`
|
||||
: undefined,
|
||||
documentWithCaptionMessage: msg?.message?.documentWithCaptionMessage?.message?.documentMessage
|
||||
? `documentWithCaptionMessage|${mediaId}${
|
||||
msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption
|
||||
? `|${msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption}`
|
||||
: ''
|
||||
}`
|
||||
: undefined,
|
||||
};
|
||||
|
||||
@@ -1035,6 +1051,10 @@ export class DifyService {
|
||||
}
|
||||
}
|
||||
|
||||
private isImageMessage(content: string) {
|
||||
return content.includes('imageMessage');
|
||||
}
|
||||
|
||||
private async initNewSession(
|
||||
instance: any,
|
||||
remoteJid: string,
|
||||
@@ -1057,7 +1077,7 @@ export class DifyService {
|
||||
|
||||
if (dify.botType === 'chatBot') {
|
||||
endpoint += '/chat-messages';
|
||||
const payload = {
|
||||
const payload: any = {
|
||||
inputs: {
|
||||
remoteJid: remoteJid,
|
||||
pushName: pushName,
|
||||
@@ -1071,6 +1091,19 @@ export class DifyService {
|
||||
user: remoteJid,
|
||||
};
|
||||
|
||||
if (this.isImageMessage(content)) {
|
||||
const contentSplit = content.split('|');
|
||||
|
||||
payload.files = [
|
||||
{
|
||||
type: 'image',
|
||||
transfer_method: 'remote_url',
|
||||
url: contentSplit[1].split('?')[0],
|
||||
},
|
||||
];
|
||||
payload.query = contentSplit[2];
|
||||
}
|
||||
|
||||
await instance.client.presenceSubscribe(remoteJid);
|
||||
|
||||
await instance.client.sendPresenceUpdate('composing', remoteJid);
|
||||
@@ -1112,7 +1145,7 @@ export class DifyService {
|
||||
|
||||
if (dify.botType === 'textGenerator') {
|
||||
endpoint += '/completion-messages';
|
||||
const payload = {
|
||||
const payload: any = {
|
||||
inputs: {
|
||||
query: content,
|
||||
pushName: pushName,
|
||||
@@ -1126,6 +1159,19 @@ export class DifyService {
|
||||
user: remoteJid,
|
||||
};
|
||||
|
||||
if (this.isImageMessage(content)) {
|
||||
const contentSplit = content.split('|');
|
||||
|
||||
payload.files = [
|
||||
{
|
||||
type: 'image',
|
||||
transfer_method: 'remote_url',
|
||||
url: contentSplit[1].split('?')[0],
|
||||
},
|
||||
];
|
||||
payload.inputs.query = contentSplit[2];
|
||||
}
|
||||
|
||||
await instance.client.presenceSubscribe(remoteJid);
|
||||
|
||||
await instance.client.sendPresenceUpdate('composing', remoteJid);
|
||||
@@ -1167,7 +1213,7 @@ export class DifyService {
|
||||
|
||||
if (dify.botType === 'agent') {
|
||||
endpoint += '/chat-messages';
|
||||
const payload = {
|
||||
const payload: any = {
|
||||
inputs: {
|
||||
remoteJid: remoteJid,
|
||||
pushName: pushName,
|
||||
@@ -1181,6 +1227,19 @@ export class DifyService {
|
||||
user: remoteJid,
|
||||
};
|
||||
|
||||
if (this.isImageMessage(content)) {
|
||||
const contentSplit = content.split('|');
|
||||
|
||||
payload.files = [
|
||||
{
|
||||
type: 'image',
|
||||
transfer_method: 'remote_url',
|
||||
url: contentSplit[1].split('?')[0],
|
||||
},
|
||||
];
|
||||
payload.query = contentSplit[2];
|
||||
}
|
||||
|
||||
await instance.client.presenceSubscribe(remoteJid);
|
||||
|
||||
await instance.client.sendPresenceUpdate('composing', remoteJid);
|
||||
@@ -1247,7 +1306,7 @@ export class DifyService {
|
||||
|
||||
if (dify.botType === 'workflow') {
|
||||
endpoint += '/workflows/run';
|
||||
const payload = {
|
||||
const payload: any = {
|
||||
inputs: {
|
||||
query: content,
|
||||
remoteJid: remoteJid,
|
||||
@@ -1260,6 +1319,19 @@ export class DifyService {
|
||||
user: remoteJid,
|
||||
};
|
||||
|
||||
if (this.isImageMessage(content)) {
|
||||
const contentSplit = content.split('|');
|
||||
|
||||
payload.files = [
|
||||
{
|
||||
type: 'image',
|
||||
transfer_method: 'remote_url',
|
||||
url: contentSplit[1].split('?')[0],
|
||||
},
|
||||
];
|
||||
payload.inputs.query = contentSplit[2];
|
||||
}
|
||||
|
||||
await instance.client.presenceSubscribe(remoteJid);
|
||||
|
||||
await instance.client.sendPresenceUpdate('composing', remoteJid);
|
||||
@@ -1410,7 +1482,7 @@ export class DifyService {
|
||||
|
||||
if (dify.botType === 'chatBot') {
|
||||
endpoint += '/chat-messages';
|
||||
const payload = {
|
||||
const payload: any = {
|
||||
inputs: {
|
||||
remoteJid: remoteJid,
|
||||
pushName: pushName,
|
||||
@@ -1424,6 +1496,19 @@ export class DifyService {
|
||||
user: remoteJid,
|
||||
};
|
||||
|
||||
if (this.isImageMessage(content)) {
|
||||
const contentSplit = content.split('|');
|
||||
|
||||
payload.files = [
|
||||
{
|
||||
type: 'image',
|
||||
transfer_method: 'remote_url',
|
||||
url: contentSplit[1].split('?')[0],
|
||||
},
|
||||
];
|
||||
payload.query = contentSplit[2];
|
||||
}
|
||||
|
||||
await instance.client.presenceSubscribe(remoteJid);
|
||||
|
||||
await instance.client.sendPresenceUpdate('composing', remoteJid);
|
||||
@@ -1465,7 +1550,7 @@ export class DifyService {
|
||||
|
||||
if (dify.botType === 'textGenerator') {
|
||||
endpoint += '/completion-messages';
|
||||
const payload = {
|
||||
const payload: any = {
|
||||
inputs: {
|
||||
query: content,
|
||||
remoteJid: remoteJid,
|
||||
@@ -1479,6 +1564,19 @@ export class DifyService {
|
||||
user: remoteJid,
|
||||
};
|
||||
|
||||
if (this.isImageMessage(content)) {
|
||||
const contentSplit = content.split('|');
|
||||
|
||||
payload.files = [
|
||||
{
|
||||
type: 'image',
|
||||
transfer_method: 'remote_url',
|
||||
url: contentSplit[1].split('?')[0],
|
||||
},
|
||||
];
|
||||
payload.inputs.query = contentSplit[2];
|
||||
}
|
||||
|
||||
await instance.client.presenceSubscribe(remoteJid);
|
||||
|
||||
await instance.client.sendPresenceUpdate('composing', remoteJid);
|
||||
@@ -1520,7 +1618,7 @@ export class DifyService {
|
||||
|
||||
if (dify.botType === 'agent') {
|
||||
endpoint += '/chat-messages';
|
||||
const payload = {
|
||||
const payload: any = {
|
||||
inputs: {
|
||||
remoteJid: remoteJid,
|
||||
pushName: pushName,
|
||||
@@ -1534,6 +1632,19 @@ export class DifyService {
|
||||
user: remoteJid,
|
||||
};
|
||||
|
||||
if (this.isImageMessage(content)) {
|
||||
const contentSplit = content.split('|');
|
||||
|
||||
payload.files = [
|
||||
{
|
||||
type: 'image',
|
||||
transfer_method: 'remote_url',
|
||||
url: contentSplit[1].split('?')[0],
|
||||
},
|
||||
];
|
||||
payload.query = contentSplit[2];
|
||||
}
|
||||
|
||||
await instance.client.presenceSubscribe(remoteJid);
|
||||
|
||||
await instance.client.sendPresenceUpdate('composing', remoteJid);
|
||||
@@ -1606,7 +1717,7 @@ export class DifyService {
|
||||
|
||||
if (dify.botType === 'workflow') {
|
||||
endpoint += '/workflows/run';
|
||||
const payload = {
|
||||
const payload: any = {
|
||||
inputs: {
|
||||
query: content,
|
||||
remoteJid: remoteJid,
|
||||
@@ -1620,6 +1731,19 @@ export class DifyService {
|
||||
user: remoteJid,
|
||||
};
|
||||
|
||||
if (this.isImageMessage(content)) {
|
||||
const contentSplit = content.split('|');
|
||||
|
||||
payload.files = [
|
||||
{
|
||||
type: 'image',
|
||||
transfer_method: 'remote_url',
|
||||
url: contentSplit[1].split('?')[0],
|
||||
},
|
||||
];
|
||||
payload.inputs.query = contentSplit[2];
|
||||
}
|
||||
|
||||
await instance.client.presenceSubscribe(remoteJid);
|
||||
|
||||
await instance.client.sendPresenceUpdate('composing', remoteJid);
|
||||
|
||||
@@ -38,6 +38,23 @@ const bucketExists = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const setBucketPolicy = async () => {
|
||||
if (minioClient) {
|
||||
const policy = {
|
||||
Version: '2012-10-17',
|
||||
Statement: [
|
||||
{
|
||||
Effect: 'Allow',
|
||||
Principal: '*',
|
||||
Action: ['s3:GetObject'],
|
||||
Resource: [`arn:aws:s3:::${bucketName}/*`],
|
||||
},
|
||||
],
|
||||
};
|
||||
await minioClient.setBucketPolicy(bucketName, JSON.stringify(policy));
|
||||
}
|
||||
};
|
||||
|
||||
const createBucket = async () => {
|
||||
if (minioClient) {
|
||||
try {
|
||||
@@ -46,6 +63,8 @@ const createBucket = async () => {
|
||||
await minioClient.makeBucket(bucketName);
|
||||
}
|
||||
|
||||
await setBucketPolicy();
|
||||
|
||||
logger.info(`S3 Bucket ${bucketName} - ON`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user