mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-20 04:29:16 +00:00
diaglogflow wit media
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const {get, reply} = require('../adapter')
|
||||
const {get, reply, getIA} = require('../adapter')
|
||||
const {saveExternalFile} = require('./handle')
|
||||
|
||||
const getMessages = async (message) => {
|
||||
@@ -16,7 +16,11 @@ const responseMessages = async (step) => {
|
||||
}
|
||||
|
||||
const bothResponse = async (message) => {
|
||||
const data = await get(message)
|
||||
const data = await getIA(message)
|
||||
if(data && data.media){
|
||||
const file = await saveExternalFile(data.media)
|
||||
return {...data,...{media:file}}
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -12,17 +12,22 @@ const cleanNumber = (number) => {
|
||||
const saveExternalFile = (url) => new Promise((resolve, reject) => {
|
||||
const ext = url.split('.').pop()
|
||||
const checkProtocol = url.split('/').includes('https:');
|
||||
console.log(checkProtocol)
|
||||
const handleHttp = checkProtocol ? https : http;
|
||||
const name = `${Date.now()}.${ext}`;
|
||||
const file = fs.createWriteStream(`./mediaSend/${name}`);
|
||||
const request = handleHttp.get(url, function(response) {
|
||||
const ext = response.headers['content-type'].split('/').pop()
|
||||
console.log(url)
|
||||
handleHttp.get(url, function(response) {
|
||||
console.log('aaaa')
|
||||
response.pipe(file);
|
||||
file.on('finish', function() {
|
||||
file.close(); // close() is async, call cb after close completes.
|
||||
resolve(name)
|
||||
});
|
||||
file.on('error', function() {
|
||||
console.log('errro')
|
||||
file.close(); // close() is async, call cb after close completes.
|
||||
resolve(null)
|
||||
});
|
||||
});
|
||||
})
|
||||
module.exports = {cleanNumber, saveExternalFile}
|
||||
Reference in New Issue
Block a user