new(basic.gblib): Facebook added.
This commit is contained in:
parent
b7bcd4f4c8
commit
a4995e7f03
2 changed files with 69 additions and 38 deletions
|
@ -15,7 +15,7 @@
|
|||
"Alan Perdomo <alanperdomo@hotmail.com>"
|
||||
],
|
||||
"engines": {
|
||||
"node": "=20.15.0"
|
||||
"node": "=20.17.0"
|
||||
},
|
||||
"license": "AGPL-3.0",
|
||||
"preferGlobal": true,
|
||||
|
|
|
@ -69,6 +69,7 @@ import { SecService } from '../../security.gbapp/services/SecService.js';
|
|||
import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';
|
||||
import retry from 'async-retry';
|
||||
import { BlobServiceClient, BlockBlobClient, StorageSharedKeyCredential } from '@azure/storage-blob';
|
||||
import { FacebookAdsApi, Page } from 'facebook-nodejs-business-sdk';
|
||||
|
||||
import { md5 } from 'js-md5';
|
||||
import { GBUtil } from '../../../src/util.js';
|
||||
|
@ -1765,7 +1766,7 @@ export class SystemKeywords {
|
|||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public async getCustomToken({ pid, tokenName }) {
|
||||
const { min } = await DialogKeywords.getProcessInfo(pid);
|
||||
|
@ -2764,6 +2765,36 @@ export class SystemKeywords {
|
|||
);
|
||||
}
|
||||
|
||||
public async postToFacebook({ pid, imagePath, caption, pageId }) {
|
||||
// Obtendo informações do processo para logs (ajuste conforme necessário)
|
||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||
|
||||
// Leitura do arquivo de imagem
|
||||
const imageBuffer = Fs.readFileSync(Path.resolve(imagePath));
|
||||
|
||||
// Criação de um arquivo temporário para enviar
|
||||
const tempFilePath = Path.resolve('temp_image.jpg');
|
||||
Fs.writeFileSync(tempFilePath, imageBuffer);
|
||||
|
||||
// Publicação da imagem
|
||||
const page = new Page(pageId);
|
||||
const response = await page.createFeed({
|
||||
message: caption,
|
||||
attached_media: [
|
||||
{
|
||||
media_fbid: tempFilePath,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Log do resultado
|
||||
GBLogEx.info(min, `Imagem publicada no Facebook: ${JSON.stringify(response)}`);
|
||||
|
||||
// Limpeza do arquivo temporário
|
||||
Fs.unlinkSync(tempFilePath);
|
||||
}
|
||||
|
||||
|
||||
public async postToInstagram({ pid, username, password, imagePath, caption }) {
|
||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue