UNPKG

onxy-messaging

Version:

A Node.js module for sending WhatsApp messages using onyxberry.com/services/wapi

61 lines (49 loc) 1.65 kB
const axios = require('axios'); const BASE_URL = 'https://onyxberry.com/services/wapi/api2'; class WhatsAppAPI { constructor(yourId, apiKey) { this.yourId = yourId; this.apiKey = apiKey; } async sendSimpleTextMessage(number, message) { const url = `${BASE_URL}/sendtext/${this.yourId}/${this.apiKey}`; const data = { number, message }; try { const response = await axios.post(url, data); return response.data; } catch (error) { return { error: error.message }; } } async sendMediaFromURL(number, url, caption = '') { const apiUrl = `${BASE_URL}/sendFromURL/${this.yourId}/${this.apiKey}`; const data = { number, url, caption }; try { const response = await axios.post(apiUrl, data); return response.data; } catch (error) { return { error: error.message }; } } async sendTextInGroup(groupName, message) { const apiUrl = `${BASE_URL}/sendTextInGroup/${this.yourId}/${this.apiKey}`; const data = { groupName, message }; try { const response = await axios.post(apiUrl, data); return response.data; } catch (error) { return { error: error.message }; } } async sendMediaFromURLInGroup(groupName, url, caption = '') { const apiUrl = `${BASE_URL}/sendFromURLInGroup/${this.yourId}/${this.apiKey}`; const data = { groupName, url, caption }; try { const response = await axios.post(apiUrl, data); return response.data; } catch (error) { return { error: error.message }; } } } module.exports = WhatsAppAPI;