11import { whatsappClient } from './utils/client'
2- import { AudioMessage , ListInteractionMessage , TextMessage } from '@wapijs/wapi.js'
2+ import { ListInteractionMessage , TextMessage } from '@wapijs/wapi.js'
33
44function init ( ) {
55 whatsappClient . on ( 'Ready' , ( ) => {
66 console . log ( 'Client is ready' )
77 } )
88
99 const faq = {
10- " What is wapijs" : [
10+ ' What is wapijs' : [
1111 {
12- question : " What is wapi.js?" ,
13- answer : " wapi.js is a Tyepscript library for building WhatsApp chatbots."
12+ question : ' What is wapi.js?' ,
13+ answer : ' wapi.js is a Tyepscript library for building WhatsApp chatbots.'
1414 } ,
1515 {
16- question : " Main features of wapi.js?" ,
17- answer : " Object-oriented design, single client, easy messaging, event handling, media upload."
16+ question : ' Main features of wapi.js?' ,
17+ answer : ' Object-oriented design, single client, easy messaging, event handling, media upload.'
1818 } ,
1919 {
20- question : " Can I build AI chatbots with wapi.js? ewfjbesjkfbewjfgbjwekfknwekjnfwefwefwef" ,
20+ question : ' Can I build AI chatbots with wapi.js?' ,
2121 answer : "wapi.js itself doesn't have AI, but you can integrate with NLU services."
22- } ,
22+ }
2323 ] ,
24- " Getting Started" : [
24+ ' Getting Started' : [
2525 {
26- question : " How do I get started with wapi.js?" ,
27- answer : " Check out the docs at https://wapijs.co/docs and use the \ "create-wapi-bot\ " template."
26+ question : ' How do I get started with wapi.js?' ,
27+ answer : ' Check out the docs at https://wapijs.co/docs and use the "create-wapi-bot" template.'
2828 } ,
2929 {
30- question : " Is wapi.js easy to learn?" ,
31- answer : " Yes, designed for all levels. Docs and examples help you get started quickly."
32- } ,
30+ question : ' Is wapi.js easy to learn?' ,
31+ answer : ' Yes, designed for all levels. Docs and examples help you get started quickly.'
32+ }
3333 ] ,
34- " Capabilities" : [
34+ Capabilities : [
3535 {
36- question : " What kind of chatbots can I build?" ,
37- answer : " Customer support, marketing, notifications, and more! Leverage WhatsApp Business API."
36+ question : ' What kind of chatbots can I build?' ,
37+ answer : ' Customer support, marketing, notifications, and more! Leverage WhatsApp Business API.'
3838 } ,
3939 {
40- question : " Can I integrate wapi.js with other systems?" ,
41- answer : " Absolutely! Integrate with existing backend system."
40+ question : ' Can I integrate wapi.js with other systems?' ,
41+ answer : ' Absolutely! Integrate with existing backend system.'
4242 } ,
4343 {
44- question : " Are there examples of chatbots built with wapi.js?" ,
44+ question : ' Are there examples of chatbots built with wapi.js?' ,
4545 answer : "It's in beta, so not many yet. Be among the first to build and share yours!"
4646 }
4747 ] ,
48- " Help & Support" : [
48+ ' Help & Support' : [
4949 {
50- question : "Is wapi.js free and open-source?" ,
50+ question :
51+ 'Is wapi.js free and open-source? qwerrqwrf3r3r32r23r23r23r23r2rqrqrerere23re23r23re' ,
5152 answer : "Yes, it's completely free and open-source under the Apache 2.0 License."
5253 } ,
5354 {
54- question : " Where can I get help or support for wapi.js?" ,
55- answer : " Create an issue on our GitHub repository: https://github.com/sarthakjdev/wapi.js/issues."
56- } ,
55+ question : ' Where can I get help or support for wapi.js?' ,
56+ answer : ' Create an issue on our GitHub repository: https://github.com/sarthakjdev/wapi.js/issues.'
57+ }
5758 ]
5859 }
5960
60-
61-
62-
63-
6461 const listMessage = new ListInteractionMessage ( {
6562 bodyText : 'Welcome to Wapi.js' ,
6663 buttonText : 'Ask questions' ,
@@ -83,11 +80,10 @@ function init() {
8380 whatsappClient . on ( 'TextMessage' , async message => {
8481 console . log ( 'Text Message' )
8582 if ( message . text . data . text . toLowerCase ( ) === 'hello' ) {
86- const response = await message . client . message . send ( {
83+ await message . client . message . send ( {
8784 message : listMessage ,
8885 phoneNumber : message . context . from
8986 } )
90- console . log ( { response : JSON . stringify ( response ) } )
9187 } else {
9288 await message . reply ( {
9389 message : new TextMessage ( {
@@ -97,7 +93,7 @@ function init() {
9793 }
9894 } )
9995
100- whatsappClient . on ( 'ListInteraction' , async ( message ) => {
96+ whatsappClient . on ( 'ListInteraction' , async message => {
10197 console . log ( 'List Interaction' , message )
10298
10399 // it would be something like : section-1-question-1
@@ -106,8 +102,6 @@ function init() {
106102 const sectionIndex = parseInt ( messageListId . split ( '-' ) [ 1 ] ) - 1
107103 const questionIndex = parseInt ( messageListId . split ( '-' ) [ 3 ] ) - 1
108104
109- console . log ( { messageListId, sectionIndex, questionIndex } )
110-
111105 // @ts -ignore
112106 const answerToReply = faq [ Object . keys ( faq ) [ sectionIndex ] ] [ questionIndex ] . answer
113107
@@ -116,7 +110,6 @@ function init() {
116110 text : answerToReply
117111 } )
118112 } )
119-
120113 } )
121114
122115 whatsappClient . on ( 'Error' , error => {
0 commit comments