fix(WhatsappDirectLine): update sendFileToDevice to default isViewOnce to true and clean up header example
Some checks are pending
GBCI / build (push) Waiting to run
Some checks are pending
GBCI / build (push) Waiting to run
This commit is contained in:
parent
1d20dd83b0
commit
0d5a4aee3c
2 changed files with 30 additions and 21 deletions
|
@ -43,6 +43,7 @@ import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
|
||||||
import { SecService } from '../../security.gbapp/services/SecService.js';
|
import { SecService } from '../../security.gbapp/services/SecService.js';
|
||||||
import { AnalyticsService } from '../../analytics.gblib/services/AnalyticsService.js';
|
import { AnalyticsService } from '../../analytics.gblib/services/AnalyticsService.js';
|
||||||
import { MicrosoftAppCredentials } from 'botframework-connector';
|
import { MicrosoftAppCredentials } from 'botframework-connector';
|
||||||
|
import { DocxLoader } from '@langchain/community/document_loaders/fs/docx';
|
||||||
import { GBConfigService } from './GBConfigService.js';
|
import { GBConfigService } from './GBConfigService.js';
|
||||||
import { CollectionUtil, AzureText } from 'pragmatismo-io-framework';
|
import { CollectionUtil, AzureText } from 'pragmatismo-io-framework';
|
||||||
import { GuaribasUser } from '../../security.gbapp/models/index.js';
|
import { GuaribasUser } from '../../security.gbapp/models/index.js';
|
||||||
|
@ -52,7 +53,7 @@ import { createWriteStream, createReadStream } from 'fs';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import twilio from 'twilio';
|
import twilio from 'twilio';
|
||||||
import Nexmo from 'nexmo';
|
import Nexmo from 'nexmo';
|
||||||
import { join } from 'path';
|
import path, { join } from 'path';
|
||||||
import shell from 'any-shell-escape';
|
import shell from 'any-shell-escape';
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import prism from 'prism-media';
|
import prism from 'prism-media';
|
||||||
|
@ -646,6 +647,14 @@ export class GBConversationalService {
|
||||||
text.toLowerCase().endsWith('.png') ||
|
text.toLowerCase().endsWith('.png') ||
|
||||||
text.toLowerCase().endsWith('.mp4') ||
|
text.toLowerCase().endsWith('.mp4') ||
|
||||||
text.toLowerCase().endsWith('.mov');
|
text.toLowerCase().endsWith('.mov');
|
||||||
|
|
||||||
|
if (text.endsWith('-zap')) {
|
||||||
|
let packagePath = GBUtil.getGBAIPath(min.botId, `gbkb`);
|
||||||
|
const localName = path.join('work', packagePath, 'articles', text);
|
||||||
|
let loader = new DocxLoader(localName);
|
||||||
|
let doc = await loader.load();
|
||||||
|
text = doc[0].pageContent;
|
||||||
|
}
|
||||||
let mediaFile = !isMedia ? /(.*)\n/gim.exec(text)[0].trim() : text;
|
let mediaFile = !isMedia ? /(.*)\n/gim.exec(text)[0].trim() : text;
|
||||||
let mediaType = mediaFile.toLowerCase().endsWith('.mp4') || text.toLowerCase().endsWith('.mov') ? 'video' : 'image';
|
let mediaType = mediaFile.toLowerCase().endsWith('.mp4') || text.toLowerCase().endsWith('.mov') ? 'video' : 'image';
|
||||||
|
|
||||||
|
|
|
@ -716,7 +716,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
return `${attachment.content.title} - ${attachment.content.text}`;
|
return `${attachment.content.title} - ${attachment.content.text}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendFileToDevice(to, url, filename, caption, chatId, isViewOnce = false) {
|
public async sendFileToDevice(to, url, filename, caption, chatId, isViewOnce = true) {
|
||||||
let options;
|
let options;
|
||||||
switch (this.provider) {
|
switch (this.provider) {
|
||||||
case 'meta':
|
case 'meta':
|
||||||
|
@ -864,7 +864,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
{
|
{
|
||||||
type: 'HEADER',
|
type: 'HEADER',
|
||||||
format: mediaType.toUpperCase(), // Use IMAGE or VIDEO format
|
format: mediaType.toUpperCase(), // Use IMAGE or VIDEO format
|
||||||
example: { header_handle: [handleMedia], header_url: ['https://pragmatismo.com.br/gb-logo.png'] }
|
example: { header_handle: [handleMedia] }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'BODY',
|
type: 'BODY',
|
||||||
|
|
Loading…
Add table
Reference in a new issue