whatsapp-bot
whatsapp-bot copied to clipboard
can you please add unscreen.com api
Please add command to remove background from Gif for animated stickers using unscreen.com Api
Please Thank you
why don't you use remove.bg?
remove.bg doesn't work with video or gif
remove.bg doesn't work with video or gif
Good point. Let me see
I'm not sure if the api works for free. Because this is the result it throws at me. If you can test it, please go ahead and send me a screenshot of your console to finish the code or if you can finish it
if (isMedia) {
if (mimetype === 'video/mp4' && message.duration < 10 || mimetype === 'image/gif' && message.duration < 10) {
const mediaData = await decryptMedia(message, uaOverride)
client.reply(from, mess.wait, id)
const filename = `./media/gifnobg.${mimetype.split('/')[1]}`
await fs.writeFileSync(filename, mediaData)
fetch('https://api.unscreen.com/v1.0/videos', {
method: 'POST',
body: JSON.stringify({
video_file: filename,
format: "gif"
}),
headers: { "X-Api-Key": "API_KEY" } //API_KEY = YOUR APIKEY
})
.then(respon => respon.json())
.then(result => {
console.log(result);
})
.catch(() => {
client.reply(from, 'Error!', id)
})
} else (
client.reply(from, '[❗] *!stickerGif* 10 seconds max!', id)
)
}
hi, I found that the unscreen api is not free. So, I purchased a small subscription to tryout.
this is what I get:
can you help me please complete the code
If you didn't use my example Can you show your code? (Don't forget to cover your Token)
I used your exact examble. Didn't change it. Then I tried video_url too, but it gives the same result.
I change fetch with cURL using the api example
Send me your console log
if (isMedia) {
if (mimetype === 'video/mp4' && message.duration < 10 || mimetype === 'image/gif' && message.duration < 10) {
const mediaData = await decryptMedia(message, uaOverride)
client.reply(from, mess.wait, id)
const filename = `./media/gifnobg.${mimetype.split('/')[1]}`
await fs.writeFileSync(filename, mediaData)
await exec(`curl -X POST "https://api.unscreen.com/v1.0/videos" -H "X-Api-Key: YOUR_API_KEY" -F "video_file=${filename}"`, async function (error, stdout, stderr) {
console.log(stdout)
})
} else (
client.reply(from, '[❗] *!stickerGif* máximo 10 segundos!', id)
)
}
no messages on console
add console.log(error) console.log(stderr)
I installed curl
var request = require('request');
var fs = require('fs');
request.post({
url: 'https://api.remove.bg/v1.0/removebg',
formData: {
image_file: fs.createReadStream('/path/to/file.jpg'),
size: 'auto',
},
headers: {
'X-Api-Key': 'INSERT_YOUR_API_KEY_HERE'
},
encoding: null
}, function(error, response, body) {
if(error) return console.error('Request failed:', error);
if(response.statusCode != 200) return console.error('Error:', response.statusCode, body.toString('utf8'));
fs.writeFileSync("no-bg.png", body);
});
this is from remove.bg website. Can we edit it for unscreen.com?
If you send correct parameters you can
I used this code:
if (isMedia) {
if (mimetype === 'video/mp4' && message.duration < 10 || mimetype === 'image/gif' && message.duration < 10) {
const mediaData = await decryptMedia(message, uaOverride)
client.reply(from, mess.wait, id)
const filename = `./media/gifnobg.${mimetype.split('/')[1]}`
await fs.writeFileSync(filename, mediaData)
//
request.post({
url: 'https://api.unscreen.com/v1.0/videos',
formData: {
video_file: fs.createReadStream(filename),
format: 'gif',
},
headers: {
'X-Api-Key': 'YOUR API KEY'
},
}, function(error, response, body) {
if(error) return console.error('Request failed:', error);
if(response.statusCode != 200) return console.error('Error:', response.statusCode, body.toString('utf8'));
console.log(response)
fs.writeFileSync("./media/gifnobgR.gif", body);
});
} else (
client.reply(from, '[❗] *!stickerGif* máximo 10 segundos!', id)
)
}
it seems that I sent the video, but I'm stuck here
How can wait for status to be 'done' and get video link
You need retry fetch after x time, i think you need https://api.unscreen.com/v1.0/videos/{VIDEO-ID} endpoint and check if the status is done, then use sendFileFromUrl
Thank you for helping... How can I extract video ID from body ? I couldn't. I think I have to convert it json. But how? I'm not expert.
example
{"target":["all"],"body":"Hello", "data":{"id": "373474747"}}
To get id:
const result = response.json() //response is returned by the api
VIDEO_ID = result.data.id
console.log(VIDEO_ID)
Yes I succeeded. I was able to remove bg from gif and send it as sticker.
if (isMedia) {
if (mimetype === 'video/mp4' && message.duration < 10 || mimetype === 'image/gif' && message.duration < 10) {
const mediaData = await decryptMedia(message, uaOverride)
client.reply(from, mess.wait, id)
const filename = `./media/gifnobg.${mimetype.split('/')[1]}`
await fs.writeFileSync(filename, mediaData)
//
request.post({
url: 'https://api.unscreen.com/v1.0/videos',
formData: {
video_file: fs.createReadStream(filename),
format: 'gif',
},
headers: {
'X-Api-Key': 'INSERT_YOUR_API_KEY_HERE'
},
}, function(error, response, body) {
if(error) return console.error('Request failed:', error);
if(response.statusCode != 200) return console.error('Error:', response.statusCode, body.toString('utf8'));
const resultScreen = JSON.parse(body)
const VIDEO_ID = resultScreen.data.id
console.log(VIDEO_ID)
// get video
const vurl = `https://api.unscreen.com/v1.0/videos/${VIDEO_ID}`
function poll(vurl) {
axios({
method: 'get',
url: vurl,
headers: { 'X-Api-Key': 'INSERT_YOUR_API_KEY_HERE' },
})
.then(function (response) {
// handle success
console.log(response.data);
if (response.data.data.attributes.status != 'done') {
// poll again
setTimeout(function () { poll(vurl); }, 3000);
} else {
// video processing is finished
console.log(response.data.data.attributes.result_url)
client.sendStickerfromUrl(from, response.data.data.attributes.result_url, { method: 'get' })
}
})
.catch(function (error) {
// handle error
console.log(error);
res.send(error);
});
}
poll(vurl);
});
} else (
client.reply(from, '[❗] *!stickerGif* máximo 10 segundos!', id)
)
}
break
but sendStickerfromUrl function is not sending the gif in right size so, it would not bounce like this::
Can you clean the code please? and Do you have a better method to send sticker from url in right size?
Thank you for helping
Nice, let me go home and I'll try to clean the code. And maybe you need see the method used in stickerGif to send as gif
I fixed it by resizing the video file before uploading it to unscreen.com. I used fluent-ffmpeg
Gib mal die Telefonnummer von der Bot danke
Holen Sie sich Outlook für iOShttps://aka.ms/o0ukef
Von: aymenitc [email protected] Gesendet: Saturday, January 23, 2021 6:36:11 PM An: MhankBarBar/whatsapp-bot [email protected] Cc: Subscribed [email protected] Betreff: Re: [MhankBarBar/whatsapp-bot] can you please add unscreen.com api (#173)
I fixed it by resizing the video file before uploading it to unscreen.com. I used fluent-ffmpeg
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/MhankBarBar/whatsapp-bot/issues/173#issuecomment-766146534, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASOEUMRHEABJUMRLACDE5LLS3MCIXANCNFSM4VQH2GRQ.
Ok but whatsapp bot 2 que error define the que.
On Wed, 27 Jan 2021, 23:51 reymundo1, [email protected] wrote:
Gib mal die Telefonnummer von der Bot danke
Holen Sie sich Outlook für iOShttps://aka.ms/o0ukef
Von: aymenitc [email protected] Gesendet: Saturday, January 23, 2021 6:36:11 PM An: MhankBarBar/whatsapp-bot [email protected] Cc: Subscribed [email protected] Betreff: Re: [MhankBarBar/whatsapp-bot] can you please add unscreen.com api (#173)
I fixed it by resizing the video file before uploading it to unscreen.com. I used fluent-ffmpeg
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub< https://github.com/MhankBarBar/whatsapp-bot/issues/173#issuecomment-766146534>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/ASOEUMRHEABJUMRLACDE5LLS3MCIXANCNFSM4VQH2GRQ
.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/MhankBarBar/whatsapp-bot/issues/173#issuecomment-768479910, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR5ZDX2AJMICGVDKPVLNVS3S4BKUHANCNFSM4VQH2GRQ .
Ok but whatsapp bot 2 que error define the que. … On Wed, 27 Jan 2021, 23:51 reymundo1, @.> wrote: Gib mal die Telefonnummer von der Bot danke Holen Sie sich Outlook für iOShttps://aka.ms/o0ukef ________________________________ Von: aymenitc @.> Gesendet: Saturday, January 23, 2021 6:36:11 PM An: MhankBarBar/whatsapp-bot @.> Cc: Subscribed @.> Betreff: Re: [MhankBarBar/whatsapp-bot] can you please add unscreen.com api (#173) I fixed it by resizing the video file before uploading it to unscreen.com. I used fluent-ffmpeg — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub< #173 (comment)>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/ASOEUMRHEABJUMRLACDE5LLS3MCIXANCNFSM4VQH2GRQ >. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#173 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR5ZDX2AJMICGVDKPVLNVS3S4BKUHANCNFSM4VQH2GRQ .
I'm not expert in programming. if you can contribute by modifing the code and make it better, that would be very nice
give me the number to see everything the bot can do
Holen Sie sich Outlook für iOShttps://aka.ms/o0ukef
Von: aymenitc [email protected] Gesendet: Thursday, January 28, 2021 4:12:26 PM An: MhankBarBar/whatsapp-bot [email protected] Cc: reymundo1 [email protected]; Comment [email protected] Betreff: Re: [MhankBarBar/whatsapp-bot] can you please add unscreen.com api (#173)
Ok but whatsapp bot 2 que error define the que. … On Wed, 27 Jan 2021, 23:51 reymundo1, @.> wrote: Gib mal die Telefonnummer von der Bot danke Holen Sie sich Outlook für iOShttps://aka.ms/o0ukef ________________________________ Von: aymenitc @.> Gesendet: Saturday, January 23, 2021 6:36:11 PM An: MhankBarBar/whatsapp-bot @.> Cc: Subscribed @.> Betreff: Re: [MhankBarBar/whatsapp-bot] can you please add unscreen.com api (#173https://github.com/MhankBarBar/whatsapp-bot/issues/173) I fixed it by resizing the video file before uploading it to unscreen.com. I used fluent-ffmpeg — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub< #173 (comment)https://github.com/MhankBarBar/whatsapp-bot/issues/173#issuecomment-766146534>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/ASOEUMRHEABJUMRLACDE5LLS3MCIXANCNFSM4VQH2GRQ >. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#173 (comment)https://github.com/MhankBarBar/whatsapp-bot/issues/173#issuecomment-768479910>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR5ZDX2AJMICGVDKPVLNVS3S4BKUHANCNFSM4VQH2GRQ .
I'm not expert in programming. if you can contribute by modifing the code and make it better, that would be very nice
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/MhankBarBar/whatsapp-bot/issues/173#issuecomment-769151787, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASOEUMQJD4LQX7WDSIGJ4TLS4F5FVANCNFSM4VQH2GRQ.