1.0.93 • Published 1 year ago
im-whatsapp v1.0.93
Código de ejemplo de la biblioteca de WhatsApp
Este código muestra cómo utilizar la biblioteca de WhatsApp para enviar mensajes, manejar eventos y realizar otras acciones en una aplicación de mensajería.
Importar la biblioteca de WhatsApp
import WhatsappLibrary from "../../../im-whatsapp-lib/dist";
Se importa la biblioteca de WhatsApp desde la ruta especificada.
Inicialización de la biblioteca
const wp = WhatsappLibrary();
wp.login("http://localhost:3000");
wp.setToken("personal");
Se crea una instancia de la biblioteca y se inicia la sesión de WhatsApp con la URL especificada. Se establece el token de acceso como "personal".
Envío de mensajes de texto
wp.send({
to: ["51943589001"],
content: {
text: "Testrtrt",
buttons: [
{
buttonId: "id1",
buttonText: { displayText: "Button 1" },
type: 1,
},
{
buttonId: "id2",
buttonText: { displayText: "Button 2" },
type: 1,
},
{
buttonId: "id3",
buttonText: { displayText: "Button 3" },
type: 1,
},
],
},
});
Se envía un mensaje de texto con una serie de botones incluidos. El mensaje se envía al destinatario especificado en el campo "to".
Envío de una lista
const sections = [
{
title: "Section 1",
rows: [
{ title: "Option 1", rowId: "option1" },
{
title: "Option 2",
rowId: "option2",
description: "This is a description",
},
],
},
{
title: "Section 2",
rows: [
{ title: "Option 3", rowId: "option3" },
{
title: "Option 4",
rowId: "option4",
description: "This is a description V2",
},
],
},
];
wp.send({
to: ["120363027614535735"],
content: {
text: "This is a list",
footer: "nice footer, link: https://google.com",
title: "Amazing boldfaced list title",
buttonText: "Required, text on the button to view the list",
sections,
},
});
Se envía una lista con secciones y opciones incluidas. El mensaje se envía al destinatario especificado en el campo "to".