Node.js Fetch API: Membuat Bot AI dengan 'node-fetch'
import fetch from 'node-fetch';
const handler = async (m, { conn, text }) => {
if (!text) {
m.reply('Ada yang bisa di bantu');
} else {
const apiUrl = https://api.azz.biz.id/api/alicia?q=${text}&key=nxkncwjjx;
m.reply('bntr kak ak loding...'); // Add loading message
try {
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
const result = data.respon;
m.reply(result);
} catch (error) {
console.error('There was a problem with the fetch operation:', error);
m.reply('Maaf kak, api lagi emror');
}
} };
handler.command = handler.help = ['c-ai']; handler.tags = ['ai']; handler.premium = false; handler.limit = false;
export default handler;
原文地址: https://www.cveoy.top/t/topic/o7lC 著作权归作者所有。请勿转载和采集!