Compare commits
72 Commits
npmBot
...
add-licens
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b676451dc1 | ||
|
|
29b9339771 | ||
|
|
30197e7502 | ||
|
|
973bda9cce | ||
|
|
09511c6d03 | ||
|
|
768f2a596a | ||
|
|
c973b988c6 | ||
|
|
150a211373 | ||
|
|
836e9ff128 | ||
|
|
3e13b37224 | ||
|
|
8c0a3a9f9c | ||
|
|
b8eb4811fe | ||
|
|
7baf3aa0fa | ||
|
|
736751afd3 | ||
|
|
7c5e343919 | ||
|
|
336470060c | ||
|
|
5967fbc35e | ||
|
|
afe893c1a3 | ||
|
|
65c76ac732 | ||
|
|
c5329eda93 | ||
|
|
54d3e68d87 | ||
|
|
117e0949d6 | ||
|
|
574b568f94 | ||
|
|
e4df23516f | ||
|
|
75073e5e03 | ||
|
|
8c12bffb8d | ||
|
|
8870677027 | ||
|
|
678da0d8cf | ||
|
|
3bb0dbd2a4 | ||
|
|
d1a38ba1f5 | ||
|
|
758c284787 | ||
|
|
46a18489a0 | ||
|
|
e5d1a0096e | ||
|
|
fc2d0b6e07 | ||
|
|
46aff50616 | ||
|
|
d0655737f1 | ||
|
|
e936c4d312 | ||
|
|
3bf8cf6d03 | ||
|
|
e4cffc7282 | ||
|
|
09dc41d685 | ||
|
|
2aae4fe6e9 | ||
|
|
e71e9f372b | ||
|
|
595941341d | ||
|
|
ff7eb53eef | ||
|
|
eeb04e1615 | ||
|
|
9e358e1c24 | ||
|
|
dc8c28305f | ||
|
|
d53380616e | ||
|
|
416deb477c | ||
|
|
d4be542a91 | ||
|
|
6566ba30a0 | ||
|
|
90a14a9e1b | ||
|
|
0b0569b783 | ||
|
|
c58bc1ce91 | ||
|
|
6288eefa99 | ||
|
|
11063d120d | ||
|
|
507e62e049 | ||
|
|
2a1ade4f25 | ||
|
|
4ca9d1418c | ||
|
|
2f653468e6 | ||
|
|
60367476d8 | ||
|
|
ca46a66283 | ||
|
|
7b0779d552 | ||
|
|
596f56b708 | ||
|
|
1535d4cec0 | ||
|
|
29db39c642 | ||
|
|
9c7f90a102 | ||
|
|
401aa1a17d | ||
|
|
07f3c114e0 | ||
|
|
4924eaef2c | ||
|
|
1513186a45 | ||
|
|
23ceb9fe14 |
12
.gitignore
vendored
12
.gitignore
vendored
@@ -64,3 +64,15 @@ typings/
|
|||||||
|
|
||||||
#session whatsappwebjs json file
|
#session whatsappwebjs json file
|
||||||
whatsapp-web.js/session.json
|
whatsapp-web.js/session.json
|
||||||
|
|
||||||
|
# ignore file in the generated website section
|
||||||
|
website-generator/public/pages/*
|
||||||
|
|
||||||
|
# ignore ejs.html files
|
||||||
|
website-generator/public/templates/*/*.ejs.html
|
||||||
|
|
||||||
|
# Not IPFS file in the direcotry
|
||||||
|
!website-generator/public/pages/ipfs-deploy.sh
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
339
LICENSE
Normal file
339
LICENSE
Normal file
@@ -0,0 +1,339 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
License is intended to guarantee your freedom to share and change free
|
||||||
|
software--to make sure the software is free for all its users. This
|
||||||
|
General Public License applies to most of the Free Software
|
||||||
|
Foundation's software and to any other program whose authors commit to
|
||||||
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
|
the GNU Lesser General Public License instead.) You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
this service if you wish), that you receive source code or can get it
|
||||||
|
if you want it, that you can change the software or use pieces of it
|
||||||
|
in new free programs; and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
anyone to deny you these rights or to ask you to surrender the rights.
|
||||||
|
These restrictions translate to certain responsibilities for you if you
|
||||||
|
distribute copies of the software, or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must give the recipients all the rights that
|
||||||
|
you have. You must make sure that they, too, receive or can get the
|
||||||
|
source code. And you must show them these terms so they know their
|
||||||
|
rights.
|
||||||
|
|
||||||
|
We protect your rights with two steps: (1) copyright the software, and
|
||||||
|
(2) offer you this license which gives you legal permission to copy,
|
||||||
|
distribute and/or modify the software.
|
||||||
|
|
||||||
|
Also, for each author's protection and ours, we want to make certain
|
||||||
|
that everyone understands that there is no warranty for this free
|
||||||
|
software. If the software is modified by someone else and passed on, we
|
||||||
|
want its recipients to know that what they have is not the original, so
|
||||||
|
that any problems introduced by others will not reflect on the original
|
||||||
|
authors' reputations.
|
||||||
|
|
||||||
|
Finally, any free program is threatened constantly by software
|
||||||
|
patents. We wish to avoid the danger that redistributors of a free
|
||||||
|
program will individually obtain patent licenses, in effect making the
|
||||||
|
program proprietary. To prevent this, we have made it clear that any
|
||||||
|
patent must be licensed for everyone's free use or not licensed at all.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License applies to any program or other work which contains
|
||||||
|
a notice placed by the copyright holder saying it may be distributed
|
||||||
|
under the terms of this General Public License. The "Program", below,
|
||||||
|
refers to any such program or work, and a "work based on the Program"
|
||||||
|
means either the Program or any derivative work under copyright law:
|
||||||
|
that is to say, a work containing the Program or a portion of it,
|
||||||
|
either verbatim or with modifications and/or translated into another
|
||||||
|
language. (Hereinafter, translation is included without limitation in
|
||||||
|
the term "modification".) Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running the Program is not restricted, and the output from the Program
|
||||||
|
is covered only if its contents constitute a work based on the
|
||||||
|
Program (independent of having been made by running the Program).
|
||||||
|
Whether that is true depends on what the Program does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Program's
|
||||||
|
source code as you receive it, in any medium, provided that you
|
||||||
|
conspicuously and appropriately publish on each copy an appropriate
|
||||||
|
copyright notice and disclaimer of warranty; keep intact all the
|
||||||
|
notices that refer to this License and to the absence of any warranty;
|
||||||
|
and give any other recipients of the Program a copy of this License
|
||||||
|
along with the Program.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy, and
|
||||||
|
you may at your option offer warranty protection in exchange for a fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Program or any portion
|
||||||
|
of it, thus forming a work based on the Program, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) You must cause the modified files to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
b) You must cause any work that you distribute or publish, that in
|
||||||
|
whole or in part contains or is derived from the Program or any
|
||||||
|
part thereof, to be licensed as a whole at no charge to all third
|
||||||
|
parties under the terms of this License.
|
||||||
|
|
||||||
|
c) If the modified program normally reads commands interactively
|
||||||
|
when run, you must cause it, when started running for such
|
||||||
|
interactive use in the most ordinary way, to print or display an
|
||||||
|
announcement including an appropriate copyright notice and a
|
||||||
|
notice that there is no warranty (or else, saying that you provide
|
||||||
|
a warranty) and that users may redistribute the program under
|
||||||
|
these conditions, and telling the user how to view a copy of this
|
||||||
|
License. (Exception: if the Program itself is interactive but
|
||||||
|
does not normally print such an announcement, your work based on
|
||||||
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Program,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Program, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Program.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Program
|
||||||
|
with the Program (or with a work based on the Program) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may copy and distribute the Program (or a work based on it,
|
||||||
|
under Section 2) in object code or executable form under the terms of
|
||||||
|
Sections 1 and 2 above provided that you also do one of the following:
|
||||||
|
|
||||||
|
a) Accompany it with the complete corresponding machine-readable
|
||||||
|
source code, which must be distributed under the terms of Sections
|
||||||
|
1 and 2 above on a medium customarily used for software interchange; or,
|
||||||
|
|
||||||
|
b) Accompany it with a written offer, valid for at least three
|
||||||
|
years, to give any third party, for a charge no more than your
|
||||||
|
cost of physically performing source distribution, a complete
|
||||||
|
machine-readable copy of the corresponding source code, to be
|
||||||
|
distributed under the terms of Sections 1 and 2 above on a medium
|
||||||
|
customarily used for software interchange; or,
|
||||||
|
|
||||||
|
c) Accompany it with the information you received as to the offer
|
||||||
|
to distribute corresponding source code. (This alternative is
|
||||||
|
allowed only for noncommercial distribution and only if you
|
||||||
|
received the program in object code or executable form with such
|
||||||
|
an offer, in accord with Subsection b above.)
|
||||||
|
|
||||||
|
The source code for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For an executable work, complete source
|
||||||
|
code means all the source code for all modules it contains, plus any
|
||||||
|
associated interface definition files, plus the scripts used to
|
||||||
|
control compilation and installation of the executable. However, as a
|
||||||
|
special exception, the source code distributed need not include
|
||||||
|
anything that is normally distributed (in either source or binary
|
||||||
|
form) with the major components (compiler, kernel, and so on) of the
|
||||||
|
operating system on which the executable runs, unless that component
|
||||||
|
itself accompanies the executable.
|
||||||
|
|
||||||
|
If distribution of executable or object code is made by offering
|
||||||
|
access to copy from a designated place, then offering equivalent
|
||||||
|
access to copy the source code from the same place counts as
|
||||||
|
distribution of the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
|
except as expressly provided under this License. Any attempt
|
||||||
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
|
void, and will automatically terminate your rights under this License.
|
||||||
|
However, parties who have received copies, or rights, from you under
|
||||||
|
this License will not have their licenses terminated so long as such
|
||||||
|
parties remain in full compliance.
|
||||||
|
|
||||||
|
5. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Program or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Program (or any work based on the
|
||||||
|
Program), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Program or works based on it.
|
||||||
|
|
||||||
|
6. Each time you redistribute the Program (or any work based on the
|
||||||
|
Program), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute or modify the Program subject to
|
||||||
|
these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties to
|
||||||
|
this License.
|
||||||
|
|
||||||
|
7. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Program at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Program by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Program.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under
|
||||||
|
any particular circumstance, the balance of the section is intended to
|
||||||
|
apply and the section as a whole is intended to apply in other
|
||||||
|
circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system, which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Program under this License
|
||||||
|
may add an explicit geographical distribution limitation excluding
|
||||||
|
those countries, so that distribution is permitted only in or among
|
||||||
|
countries not thus excluded. In such case, this License incorporates
|
||||||
|
the limitation as if written in the body of this License.
|
||||||
|
|
||||||
|
9. The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program
|
||||||
|
specifies a version number of this License which applies to it and "any
|
||||||
|
later version", you have the option of following the terms and conditions
|
||||||
|
either of that version or of any later version published by the Free
|
||||||
|
Software Foundation. If the Program does not specify a version number of
|
||||||
|
this License, you may choose any version ever published by the Free Software
|
||||||
|
Foundation.
|
||||||
|
|
||||||
|
10. If you wish to incorporate parts of the Program into other free
|
||||||
|
programs whose distribution conditions are different, write to the author
|
||||||
|
to ask for permission. For software which is copyrighted by the Free
|
||||||
|
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||||
|
make exceptions for this. Our decision will be guided by the two goals
|
||||||
|
of preserving the free status of all derivatives of our free software and
|
||||||
|
of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||||
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||||
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||||
|
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||||
|
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||||
|
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||||
|
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||||
|
REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||||
|
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||||
|
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||||
|
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||||
|
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||||
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program is interactive, make it output a short notice like this
|
||||||
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
|
Gnomovision version 69, Copyright (C) year name of author
|
||||||
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, the commands you use may
|
||||||
|
be called something other than `show w' and `show c'; they could even be
|
||||||
|
mouse-clicks or menu items--whatever suits your program.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||||
|
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1989
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
This General Public License does not permit incorporating your program into
|
||||||
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
|
consider it more useful to permit linking proprietary applications with the
|
||||||
|
library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License.
|
||||||
41
README.md
41
README.md
@@ -9,22 +9,53 @@ In this project we will illustrate how to build a static web page using commands
|
|||||||
## Installation
|
## Installation
|
||||||
Requirements : Node js and Npm
|
Requirements : Node js and Npm
|
||||||
|
|
||||||
### To start web generator
|
### Install web generator
|
||||||
|
|
||||||
|
First, go to the folder named **website-generator**.
|
||||||
|
Then install all the node modules.
|
||||||
```
|
```
|
||||||
cd website-generation
|
cd website-generation
|
||||||
|
npm install
|
||||||
```
|
```
|
||||||
Installation : https://github.com/Tech-club/Challenge-1/tree/master/website-generator#installation
|
|
||||||
|
|
||||||
|
### Install whatsapp bot
|
||||||
|
|
||||||
### To start whatsapp bot
|
First, go to the folder named **whatsapp-web.js**.
|
||||||
|
Then install all the node modules.
|
||||||
|
|
||||||
```
|
```
|
||||||
cd whatsapp-web.js
|
cd whatsapp-web.js
|
||||||
npm install
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
### Start the website generator
|
||||||
|
Make sure you are in **website-generator** directory. Then type the following command :
|
||||||
|
```
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
For more information on deploying the server in IPFS, please click the following link:
|
||||||
|
https://github.com/Tech-club/Challenge-1/tree/master/website-generator#installation
|
||||||
|
|
||||||
|
### Start whatsapp bot
|
||||||
|
|
||||||
|
Make sure you are in **whatsapp-web.js** directory. Then type the following command :
|
||||||
|
```
|
||||||
npm start
|
npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Start generating websites with whatsapp
|
||||||
|
|
||||||
|
You need to start both website-generator and whatsapp-bot.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Contributors
|
### Contributors
|
||||||
1. Akilan Selvacoumar : as251@hw.ac.uk
|
1. Akilan Selvacoumar: akilan@hwtech.club (https://akilan.io)
|
||||||
2. Gaurav Gosain : gg68@hw.ac.uk
|
2. Mohammed Ashab Uddin : https://ashab272000.github.io/dist/
|
||||||
|
3. Baber Jan
|
||||||
|
4. Preeti Rawat
|
||||||
|
5. Gaurav Gosain: gg68@hw.ac.uk
|
||||||
|
6. Nicole Tobe: https://github.com/tobenxe
|
||||||
|
7. Humaid AlQassimi: me@humaidq.ae(https://humaidq.ae)
|
||||||
|
(Website generator based on: https://humaidq.ae/projects/shopsheet/)
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ exports.generate = function (req, res) {
|
|||||||
//we can now manipulate the data
|
//we can now manipulate the data
|
||||||
let result = req.body.companyName;
|
let result = req.body.companyName;
|
||||||
|
|
||||||
//console.log(req.body);
|
|
||||||
|
|
||||||
let dir = './public/pages/' + req.body.companyName;
|
let dir = './public/pages/' + req.body.companyName;
|
||||||
|
|
||||||
if (!fs.existsSync(dir)) {
|
if (!fs.existsSync(dir)) {
|
||||||
@@ -52,7 +50,7 @@ exports.generate = function (req, res) {
|
|||||||
let templateContent = JSON.parse(template);
|
let templateContent = JSON.parse(template);
|
||||||
|
|
||||||
for (var i = 0; i < templateContent.templates.length; i++) {
|
for (var i = 0; i < templateContent.templates.length; i++) {
|
||||||
if (templateContent.templates[i].template_name == "Colo_Shop") {
|
if (templateContent.templates[i].template_name == req.body.template) {
|
||||||
|
|
||||||
for (var j = 0; j < templateContent.templates[i].pages.length; j++) {
|
for (var j = 0; j < templateContent.templates[i].pages.length; j++) {
|
||||||
//Copying html files can be removed in the future stages
|
//Copying html files can be removed in the future stages
|
||||||
@@ -67,18 +65,6 @@ exports.generate = function (req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*fs.createReadStream('./public/Colo_Shop/index.html').pipe(fs.createWriteStream(dir + '/index.html'));
|
|
||||||
fs.createReadStream('./public/Colo_Shop/cart.html').pipe(fs.createWriteStream(dir + '/cart.html'));
|
|
||||||
fs.createReadStream('./public/Colo_Shop/contact.html').pipe(fs.createWriteStream(dir + '/contact.html'));
|
|
||||||
|
|
||||||
copy_folder('./public/Colo_Shop/styles', dir + '/styles');
|
|
||||||
copy_folder('./public/Colo_Shop/js', dir + '/js');
|
|
||||||
copy_folder('./public/Colo_Shop/plugins', dir + '/plugins');
|
|
||||||
copy_folder('./public/Colo_Shop/images', dir + '/images');
|
|
||||||
|
|
||||||
ejs2html('./public/Colo_Shop/index.ejs', req.body , dir, "index");
|
|
||||||
ejs2html('./public/Colo_Shop/cart.ejs', req.body , dir, "cart");
|
|
||||||
ejs2html('./public/Colo_Shop/contact.ejs', req.body , dir, "contact");*/
|
|
||||||
|
|
||||||
const resp = {
|
const resp = {
|
||||||
'directory': result
|
'directory': result
|
||||||
@@ -112,12 +98,10 @@ exports.deploy_ipfs = function (req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.convertCsv = function (req, res, next) {
|
exports.convertCsv = function (req, res, next) {
|
||||||
console.log(req.body);
|
|
||||||
const csvStr = req.body.csv;
|
const csvStr = req.body.csv;
|
||||||
csv()
|
csv()
|
||||||
.fromString(csvStr)
|
.fromString(csvStr)
|
||||||
.then((jsonObj) => {
|
.then((jsonObj) => {
|
||||||
console.log(jsonObj)
|
|
||||||
req.body.csv = jsonObj;
|
req.body.csv = jsonObj;
|
||||||
//delete file at path
|
//delete file at path
|
||||||
next()
|
next()
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ module.exports = function (app){
|
|||||||
// generate site
|
// generate site
|
||||||
app.post('/generate',home.convertCsv, home.generate);
|
app.post('/generate',home.convertCsv, home.generate);
|
||||||
|
|
||||||
|
app.post('/generate_with_json_data', home.generate);
|
||||||
|
|
||||||
app.get('/template_info',home.template_info);
|
app.get('/template_info',home.template_info);
|
||||||
|
|
||||||
app.get('/ipfsdeploy', home.deploy_ipfs);
|
app.get('/ipfsdeploy', home.deploy_ipfs);
|
||||||
|
|||||||
6
website-generator/package-lock.json
generated
6
website-generator/package-lock.json
generated
@@ -1132,9 +1132,9 @@
|
|||||||
"integrity": "sha1-ZMTwJfF/1Tv7RXY/rrFvAVp0dVA="
|
"integrity": "sha1-ZMTwJfF/1Tv7RXY/rrFvAVp0dVA="
|
||||||
},
|
},
|
||||||
"lodash": {
|
"lodash": {
|
||||||
"version": "4.17.15",
|
"version": "4.17.19",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
|
||||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
|
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ=="
|
||||||
},
|
},
|
||||||
"lodash.debounce": {
|
"lodash.debounce": {
|
||||||
"version": "4.0.8",
|
"version": "4.0.8",
|
||||||
|
|||||||
@@ -117,9 +117,9 @@
|
|||||||
<div class="hamburger_close"><i class="fa fa-times" aria-hidden="true"></i></div>
|
<div class="hamburger_close"><i class="fa fa-times" aria-hidden="true"></i></div>
|
||||||
<div class="hamburger_menu_content text-right">
|
<div class="hamburger_menu_content text-right">
|
||||||
<ul class="menu_top_nav">
|
<ul class="menu_top_nav">
|
||||||
<li class="menu_item"><a href="#">home</a></li>
|
<li class="menu_item"><a href="index.html">home</a></li>
|
||||||
<li class="menu_item"><a href="#">cart</a></li>
|
<li class="menu_item"><a href="cart.html">cart</a></li>
|
||||||
<li class="menu_item"><a href="#">contact</a></li>
|
<li class="menu_item"><a href="contact.html">contact</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Heriot-Watt</title>
|
<title>Test123</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="description" content="Colo Shop Template">
|
<meta name="description" content="Colo Shop Template">
|
||||||
@@ -86,7 +86,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12 text-right">
|
<div class="col-lg-12 text-right">
|
||||||
<div class="logo_container">
|
<div class="logo_container">
|
||||||
<a href="#"><img src="https://www.google.com/url?sa=i&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHeriot-Watt_University&psig=AOvVaw2fm-eoyZxj8ZIUEULdjZ5_&ust=1589820225686000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCJj1i4Osu-kCFQAAAAAdAAAAABAD" class="img-fluid" style="height:5rem;" /></a>
|
<a href="#"><img src="https://hwtech.club/images/output-onlinepngtools.png" class="img-fluid" style="height:5rem;" /></a>
|
||||||
</div>
|
</div>
|
||||||
<nav class="navbar">
|
<nav class="navbar">
|
||||||
<ul class="navbar_menu">
|
<ul class="navbar_menu">
|
||||||
@@ -117,9 +117,9 @@
|
|||||||
<div class="hamburger_close"><i class="fa fa-times" aria-hidden="true"></i></div>
|
<div class="hamburger_close"><i class="fa fa-times" aria-hidden="true"></i></div>
|
||||||
<div class="hamburger_menu_content text-right">
|
<div class="hamburger_menu_content text-right">
|
||||||
<ul class="menu_top_nav">
|
<ul class="menu_top_nav">
|
||||||
<li class="menu_item"><a href="#">home</a></li>
|
<li class="menu_item"><a href="index.html">home</a></li>
|
||||||
<li class="menu_item"><a href="#">cart</a></li>
|
<li class="menu_item"><a href="cart.html">cart</a></li>
|
||||||
<li class="menu_item"><a href="#">contact</a></li>
|
<li class="menu_item"><a href="contact.html">contact</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -289,19 +289,19 @@
|
|||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
if (localStorage.getItem('Heriot-Watt') === null) {
|
if (localStorage.getItem('Test123_50') === null) {
|
||||||
console.log("here");
|
console.log("here");
|
||||||
var arr = new Array();
|
var arr = new Array();
|
||||||
localStorage.setItem('Heriot-Watt', JSON.stringify(arr));
|
localStorage.setItem('Test123_50', JSON.stringify(arr));
|
||||||
}
|
}
|
||||||
|
|
||||||
var arr_json = JSON.parse(localStorage.getItem('Heriot-Watt'));
|
var arr_json = JSON.parse(localStorage.getItem('Test123_50'));
|
||||||
|
|
||||||
$("#checkout_items").html(arr_json.length);
|
$("#checkout_items").html(arr_json.length);
|
||||||
console.log(arr_json.length);
|
console.log(arr_json.length);
|
||||||
|
|
||||||
|
|
||||||
var arr_json = JSON.parse(localStorage.getItem('Heriot-Watt'));
|
var arr_json = JSON.parse(localStorage.getItem('Test123_50'));
|
||||||
$("#table").html("");
|
$("#table").html("");
|
||||||
var receipt = "<textarea name=\"purchases\">";
|
var receipt = "<textarea name=\"purchases\">";
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
@@ -333,12 +333,12 @@
|
|||||||
|
|
||||||
function delete_item(id) {
|
function delete_item(id) {
|
||||||
$("#table").html("");
|
$("#table").html("");
|
||||||
var arr_json = JSON.parse(localStorage.getItem('Heriot-Watt'));
|
var arr_json = JSON.parse(localStorage.getItem('Test123_50'));
|
||||||
if (id > -1) {
|
if (id > -1) {
|
||||||
arr_json.splice(id, 1);
|
arr_json.splice(id, 1);
|
||||||
}
|
}
|
||||||
console.log(id);
|
console.log(id);
|
||||||
localStorage.setItem('Heriot-Watt', JSON.stringify(arr_json));
|
localStorage.setItem('Test123_50', JSON.stringify(arr_json));
|
||||||
console.log(arr_json.length);
|
console.log(arr_json.length);
|
||||||
var receipt = "<textarea name=\"purchases\">";
|
var receipt = "<textarea name=\"purchases\">";
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
|
|||||||
@@ -100,7 +100,7 @@
|
|||||||
<li class="checkout">
|
<li class="checkout">
|
||||||
<a href="cart.html">
|
<a href="cart.html">
|
||||||
<i class="fa fa-shopping-cart" aria-hidden="true"></i>
|
<i class="fa fa-shopping-cart" aria-hidden="true"></i>
|
||||||
<span id="checkout_items" class="checkout_items">2</span>
|
<span id="checkout_items" class="checkout_items">0</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -115,6 +115,18 @@
|
|||||||
|
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
<div class="fs_menu_overlay"></div>
|
||||||
|
<div class="hamburger_menu">
|
||||||
|
<div class="hamburger_close"><i class="fa fa-times" aria-hidden="true"></i></div>
|
||||||
|
<div class="hamburger_menu_content text-right">
|
||||||
|
<ul class="menu_top_nav">
|
||||||
|
<li class="menu_item"><a href="index.html">home</a></li>
|
||||||
|
<li class="menu_item"><a href="cart.html">cart</a></li>
|
||||||
|
<li class="menu_item"><a href="#">contact</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="container contact_container">
|
<div class="container contact_container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Heriot-Watt</title>
|
<title>Test123</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="description" content="Colo Shop Template">
|
<meta name="description" content="Colo Shop Template">
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12 text-right">
|
<div class="col-lg-12 text-right">
|
||||||
<div class="logo_container">
|
<div class="logo_container">
|
||||||
<a href="#"><img src="https://www.google.com/url?sa=i&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHeriot-Watt_University&psig=AOvVaw2fm-eoyZxj8ZIUEULdjZ5_&ust=1589820225686000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCJj1i4Osu-kCFQAAAAAdAAAAABAD" class="img-fluid" style="height:5rem;" /></a>
|
<a href="#"><img src="https://hwtech.club/images/output-onlinepngtools.png" class="img-fluid" style="height:5rem;" /></a>
|
||||||
</div>
|
</div>
|
||||||
<nav class="navbar">
|
<nav class="navbar">
|
||||||
<ul class="navbar_menu">
|
<ul class="navbar_menu">
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
<li class="checkout">
|
<li class="checkout">
|
||||||
<a href="cart.html">
|
<a href="cart.html">
|
||||||
<i class="fa fa-shopping-cart" aria-hidden="true"></i>
|
<i class="fa fa-shopping-cart" aria-hidden="true"></i>
|
||||||
<span id="checkout_items" class="checkout_items">2</span>
|
<span id="checkout_items" class="checkout_items">0</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -115,6 +115,18 @@
|
|||||||
|
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
<div class="fs_menu_overlay"></div>
|
||||||
|
<div class="hamburger_menu">
|
||||||
|
<div class="hamburger_close"><i class="fa fa-times" aria-hidden="true"></i></div>
|
||||||
|
<div class="hamburger_menu_content text-right">
|
||||||
|
<ul class="menu_top_nav">
|
||||||
|
<li class="menu_item"><a href="index.html">home</a></li>
|
||||||
|
<li class="menu_item"><a href="cart.html">cart</a></li>
|
||||||
|
<li class="menu_item"><a href="#">contact</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="container contact_container">
|
<div class="container contact_container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
@@ -279,13 +291,13 @@
|
|||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
if (localStorage.getItem('Heriot-Watt') === null) {
|
if (localStorage.getItem('Test123_50') === null) {
|
||||||
console.log("here");
|
console.log("here");
|
||||||
var arr = new Array();
|
var arr = new Array();
|
||||||
localStorage.setItem('Heriot-Watt', JSON.stringify(arr));
|
localStorage.setItem('Test123_50', JSON.stringify(arr));
|
||||||
}
|
}
|
||||||
|
|
||||||
var arr_json = JSON.parse(localStorage.getItem('Heriot-Watt'));
|
var arr_json = JSON.parse(localStorage.getItem('Test123_50'));
|
||||||
|
|
||||||
$("#checkout_items").html(arr_json.length);
|
$("#checkout_items").html(arr_json.length);
|
||||||
console.log(arr_json.length);
|
console.log(arr_json.length);
|
||||||
|
|||||||
@@ -120,8 +120,8 @@
|
|||||||
<div class="hamburger_menu_content text-right">
|
<div class="hamburger_menu_content text-right">
|
||||||
<ul class="menu_top_nav">
|
<ul class="menu_top_nav">
|
||||||
<li class="menu_item"><a href="#">home</a></li>
|
<li class="menu_item"><a href="#">home</a></li>
|
||||||
<li class="menu_item"><a href="#">cart</a></li>
|
<li class="menu_item"><a href="cart.html">cart</a></li>
|
||||||
<li class="menu_item"><a href="#">contact</a></li>
|
<li class="menu_item"><a href="contact.html">contact</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -145,18 +145,15 @@
|
|||||||
<div class="col text-center">
|
<div class="col text-center">
|
||||||
<div class="section_title new_arrivals_title">
|
<div class="section_title new_arrivals_title">
|
||||||
<h2>Our Products</h2>
|
<h2>Our Products</h2>
|
||||||
|
<p><%= description %></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!---<div class="row align-items-center">
|
<!---<div class="row align-items-center">
|
||||||
<div class="col text-center">
|
<div class="col text-center">
|
||||||
<div class="new_arrivals_sorting">
|
<div class="new_arrivals_sorting">
|
||||||
<ul class="arrivals_grid_sorting clearfix button-group filters-button-group">
|
<ul class="arrivals_grid_sorting clearfix button-group filters-button-group">
|
||||||
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center active is-checked" data-filter="*">all</li>
|
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center active is-checked" data-filter="*">all</li>
|
||||||
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center" data-filter=".women">women's</li>
|
|
||||||
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center" data-filter=".accessories">accessories</li>
|
|
||||||
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center" data-filter=".men">men's</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -168,20 +165,21 @@
|
|||||||
|
|
||||||
<!-- Product 3 -->
|
<!-- Product 3 -->
|
||||||
<% for(var i = 0; i < csv.length ; i++) {%>
|
<% for(var i = 0; i < csv.length ; i++) {%>
|
||||||
<div class="product-item women">
|
<div class="product-item *">
|
||||||
<div class="product product_filter">
|
<div class="product product_filter">
|
||||||
<div class="product_image">
|
<div class="product_image">
|
||||||
<img src="<%= csv[i]['product image url'] %>" alt="">
|
<img src="<%= csv[i]['product image url'] %>" alt="">
|
||||||
</div>
|
</div>
|
||||||
<div class="favorite"></div>
|
|
||||||
<div class="product_info">
|
<div class="product_info">
|
||||||
<h6 class="product_name"><a href="#"><a><%= csv[i]["product name"] %></a></h6>
|
<h6 class="product_name"><a href="#"><a><%= csv[i]["product name"] %></a></h6>
|
||||||
|
<p><%= csv[i]["description"] %></p>
|
||||||
<div class="product_price">$<%= csv[i].cost %></div>
|
<div class="product_price">$<%= csv[i].cost %></div>
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="cart"><div class="red_button add_to_cart_button"><a onClick="additem('<%= csv[i]['product name'] %>', <%= csv[i].cost %>)" style="color:white">Add to cart</a></div></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="red_button add_to_cart_button"><a onClick="additem('<%= csv[i]['product name'] %>', <%= csv[i].cost %>)" style="color:white">Add to cart</a></div>
|
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -190,25 +188,38 @@
|
|||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<!-- Footer -->
|
||||||
|
|
||||||
<!-- Footer -->
|
<footer class="footer">
|
||||||
|
<div class="container">
|
||||||
<footer class="footer">
|
<div class="row">
|
||||||
<div class="container">
|
<div class="col-lg-12">
|
||||||
<div class="row">
|
<div class="footer_nav_container">
|
||||||
<div class="col-lg-12">
|
<div class="cr">©2018 All Rights Reserverd. This template is made with <i
|
||||||
<div class="footer_nav_container">
|
class="fa fa-heart-o" aria-hidden="true"></i> by <a href="#">Colorlib</a></div>
|
||||||
<div class="cr">©2018 All Rights Reserverd. This template is made with <i
|
|
||||||
class="fa fa-heart-o" aria-hidden="true"></i> by <a href="#">Colorlib</a></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<script src="js/jquery-3.2.1.min.js"></script>
|
<script src="js/jquery-3.2.1.min.js"></script>
|
||||||
<script src="styles/bootstrap4/popper.js"></script>
|
<script src="styles/bootstrap4/popper.js"></script>
|
||||||
<script src="styles/bootstrap4/bootstrap.min.js"></script>
|
<script src="styles/bootstrap4/bootstrap.min.js"></script>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Heriot-Watt</title>
|
<title>Test123</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="description" content="Colo Shop Template">
|
<meta name="description" content="Colo Shop Template">
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
<div class="col-lg-12 text-right">
|
<div class="col-lg-12 text-right">
|
||||||
<div class="logo_container">
|
<div class="logo_container">
|
||||||
<a href="#"><img
|
<a href="#"><img
|
||||||
src="https://www.google.com/url?sa=i&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHeriot-Watt_University&psig=AOvVaw2fm-eoyZxj8ZIUEULdjZ5_&ust=1589820225686000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCJj1i4Osu-kCFQAAAAAdAAAAABAD"
|
src="https://hwtech.club/images/output-onlinepngtools.png"
|
||||||
class="img-fluid" style="height:5rem;" /></a>
|
class="img-fluid" style="height:5rem;" /></a>
|
||||||
</div>
|
</div>
|
||||||
<nav class="navbar">
|
<nav class="navbar">
|
||||||
@@ -120,8 +120,8 @@
|
|||||||
<div class="hamburger_menu_content text-right">
|
<div class="hamburger_menu_content text-right">
|
||||||
<ul class="menu_top_nav">
|
<ul class="menu_top_nav">
|
||||||
<li class="menu_item"><a href="#">home</a></li>
|
<li class="menu_item"><a href="#">home</a></li>
|
||||||
<li class="menu_item"><a href="#">cart</a></li>
|
<li class="menu_item"><a href="cart.html">cart</a></li>
|
||||||
<li class="menu_item"><a href="#">contact</a></li>
|
<li class="menu_item"><a href="contact.html">contact</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -129,7 +129,7 @@
|
|||||||
<!-- Slider -->
|
<!-- Slider -->
|
||||||
|
|
||||||
<div class="main_slider"
|
<div class="main_slider"
|
||||||
style="background-image:url('https://ichef.bbci.co.uk/news/1024/cpsprodpb/E13E/production/_109726675_hwudubaineviewonline.jpg')">
|
style="background-image:url('https://i.ytimg.com/vi/SIQHKaMOCbU/maxresdefault.jpg')">
|
||||||
<div class="container fill_height">
|
<div class="container fill_height">
|
||||||
<div class="row align-items-center fill_height">
|
<div class="row align-items-center fill_height">
|
||||||
|
|
||||||
@@ -145,18 +145,15 @@
|
|||||||
<div class="col text-center">
|
<div class="col text-center">
|
||||||
<div class="section_title new_arrivals_title">
|
<div class="section_title new_arrivals_title">
|
||||||
<h2>Our Products</h2>
|
<h2>Our Products</h2>
|
||||||
|
<p>Loldfsdf sdfsdsdsfsd sd fsdrs d sdf </p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!---<div class="row align-items-center">
|
<!---<div class="row align-items-center">
|
||||||
<div class="col text-center">
|
<div class="col text-center">
|
||||||
<div class="new_arrivals_sorting">
|
<div class="new_arrivals_sorting">
|
||||||
<ul class="arrivals_grid_sorting clearfix button-group filters-button-group">
|
<ul class="arrivals_grid_sorting clearfix button-group filters-button-group">
|
||||||
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center active is-checked" data-filter="*">all</li>
|
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center active is-checked" data-filter="*">all</li>
|
||||||
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center" data-filter=".women">women's</li>
|
|
||||||
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center" data-filter=".accessories">accessories</li>
|
|
||||||
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center" data-filter=".men">men's</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -168,18 +165,34 @@
|
|||||||
|
|
||||||
<!-- Product 3 -->
|
<!-- Product 3 -->
|
||||||
|
|
||||||
<div class="product-item women">
|
<div class="product-item *">
|
||||||
<div class="product product_filter">
|
<div class="product product_filter">
|
||||||
<div class="product_image">
|
<div class="product_image">
|
||||||
<img src="https://www.raspberrypi.org/homepage-9df4b/static/hero-shot-33d83b8c5fa0933373dabcc9462b32a3.png" alt="">
|
<img src="https://i.stack.imgur.com/WxVXe.jpg" alt="">
|
||||||
</div>
|
</div>
|
||||||
<div class="favorite"></div>
|
|
||||||
<div class="product_info">
|
<div class="product_info">
|
||||||
<h6 class="product_name"><a href="#"><a>Raspberry Pi</a></h6>
|
<h6 class="product_name"><a href="#"><a>java</a></h6>
|
||||||
<div class="product_price">$400</div>
|
<p>We all love java fsdf sdf' sd'f 'sdf sfsdf sdf sdf</p>
|
||||||
|
<div class="product_price">$130</div>
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="cart"><div class="red_button add_to_cart_button"><a onClick="additem('java', 130)" style="color:white">Add to cart</a></div></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="product-item *">
|
||||||
|
<div class="product product_filter">
|
||||||
|
<div class="product_image">
|
||||||
|
<img src="https://images-na.ssl-images-amazon.com/images/I/41IlAcQj9nL.jpg" alt="">
|
||||||
|
</div>
|
||||||
|
<div class="product_info">
|
||||||
|
<h6 class="product_name"><a href="#"><a>C</a></h6>
|
||||||
|
<p>C lord it is</p>
|
||||||
|
<div class="product_price">$200</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="cart"><div class="red_button add_to_cart_button"><a onClick="additem('C', 200)" style="color:white">Add to cart</a></div></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="red_button add_to_cart_button"><a onClick="additem('Raspberry Pi', 400)" style="color:white">Add to cart</a></div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@@ -190,25 +203,38 @@
|
|||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<!-- Footer -->
|
||||||
|
|
||||||
<!-- Footer -->
|
<footer class="footer">
|
||||||
|
<div class="container">
|
||||||
<footer class="footer">
|
<div class="row">
|
||||||
<div class="container">
|
<div class="col-lg-12">
|
||||||
<div class="row">
|
<div class="footer_nav_container">
|
||||||
<div class="col-lg-12">
|
<div class="cr">©2018 All Rights Reserverd. This template is made with <i
|
||||||
<div class="footer_nav_container">
|
class="fa fa-heart-o" aria-hidden="true"></i> by <a href="#">Colorlib</a></div>
|
||||||
<div class="cr">©2018 All Rights Reserverd. This template is made with <i
|
|
||||||
class="fa fa-heart-o" aria-hidden="true"></i> by <a href="#">Colorlib</a></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<script src="js/jquery-3.2.1.min.js"></script>
|
<script src="js/jquery-3.2.1.min.js"></script>
|
||||||
<script src="styles/bootstrap4/popper.js"></script>
|
<script src="styles/bootstrap4/popper.js"></script>
|
||||||
<script src="styles/bootstrap4/bootstrap.min.js"></script>
|
<script src="styles/bootstrap4/bootstrap.min.js"></script>
|
||||||
@@ -220,13 +246,13 @@
|
|||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
if (localStorage.getItem('Heriot-Watt') === null) {
|
if (localStorage.getItem('Test123_50') === null) {
|
||||||
console.log("here");
|
console.log("here");
|
||||||
var arr = new Array();
|
var arr = new Array();
|
||||||
localStorage.setItem('Heriot-Watt', JSON.stringify(arr));
|
localStorage.setItem('Test123_50', JSON.stringify(arr));
|
||||||
}
|
}
|
||||||
|
|
||||||
var arr_json = JSON.parse(localStorage.getItem('Heriot-Watt'));
|
var arr_json = JSON.parse(localStorage.getItem('Test123_50'));
|
||||||
|
|
||||||
$("#checkout_items").html(arr_json.length);
|
$("#checkout_items").html(arr_json.length);
|
||||||
console.log(arr_json.length);
|
console.log(arr_json.length);
|
||||||
@@ -235,11 +261,11 @@
|
|||||||
|
|
||||||
function additem(name, price) {
|
function additem(name, price) {
|
||||||
var data = { 'name': name, 'price': price };
|
var data = { 'name': name, 'price': price };
|
||||||
var arr_json = JSON.parse(localStorage.getItem('Heriot-Watt'));
|
var arr_json = JSON.parse(localStorage.getItem('Test123_50'));
|
||||||
console.log(typeof (arr_json));
|
console.log(typeof (arr_json));
|
||||||
arr_json.push(data);
|
arr_json.push(data);
|
||||||
localStorage.setItem('Heriot-Watt', JSON.stringify(arr_json));
|
localStorage.setItem('Test123_50', JSON.stringify(arr_json));
|
||||||
console.log(JSON.parse(localStorage.getItem('Heriot-Watt')));
|
console.log(JSON.parse(localStorage.getItem('Test123_50')));
|
||||||
$('#checkout_items').html(arr_json.length);
|
$('#checkout_items').html(arr_json.length);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1031,14 +1031,11 @@ section
|
|||||||
}
|
}
|
||||||
.product-item:hover::after
|
.product-item:hover::after
|
||||||
{
|
{
|
||||||
box-shadow: 0 25px 29px rgba(63, 78, 100, 0.15);
|
|
||||||
border: solid 2px rgba(235,235,235,1);
|
|
||||||
}
|
}
|
||||||
.product
|
.product
|
||||||
{
|
{
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 340px;
|
height: 340px;
|
||||||
border-right: solid 1px #e9e9e9;
|
|
||||||
}
|
}
|
||||||
.product_image
|
.product_image
|
||||||
{
|
{
|
||||||
|
|||||||
1016
whatsapp-web.js/package-lock.json
generated
1016
whatsapp-web.js/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -4,13 +4,19 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "test.js",
|
"main": "test.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node website_test.js http://localhost:8004",
|
"test-web": "node website_test.js http://localhost:8004",
|
||||||
|
"test": "mocha",
|
||||||
"start": "node index.js"
|
"start": "node index.js"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"common-tags": "^1.8.0",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"whatsapp-web.js": "^1.7.0"
|
"whatsapp-web.js": "^1.8.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"chai": "^4.2.0",
|
||||||
|
"mocha": "^8.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,628 @@
|
|||||||
const { Website } = require("../models/website");
|
const { Website } = require("../models/website");
|
||||||
const { data } = require("../models/data");
|
const { data } = require("../models/data");
|
||||||
|
const { Product } = require('../models/product');
|
||||||
|
const { User } = require('../models/user');
|
||||||
|
const fs = require('fs');
|
||||||
|
const request = require('request');
|
||||||
|
const {stripIndents} = require('common-tags');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* user to be sent the message to
|
||||||
|
* @type { User }
|
||||||
|
*/
|
||||||
|
let user = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* input to be used in the function if exists
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
let input = null;
|
||||||
|
|
||||||
|
|
||||||
|
const base64_decode = async (base64str, file) => {
|
||||||
|
|
||||||
|
var bitmap = await Buffer.from(base64str, 'base64');
|
||||||
|
await fs.writeFileSync(file, bitmap);
|
||||||
|
console.log('****** File created from base64 encoded string ******');
|
||||||
|
|
||||||
module.exports.onWG = () => {
|
|
||||||
console.log('hello world');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.onCreate = (id, companyName) => {
|
|
||||||
|
|
||||||
//get the user
|
const saveImage = async (messageMedia, fileName) => {
|
||||||
let user = data.getUser(id);
|
let file = `../website-generator/public/images/${fileName}.jpg`;
|
||||||
if(user == undefined)
|
await base64_decode(messageMedia.data, file);
|
||||||
|
return `../../images/${fileName}.jpg`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const addProduct = (id) => {
|
||||||
|
|
||||||
|
// Create a product and select it.
|
||||||
|
//At this point all the product properties will be default
|
||||||
|
var product = new Product({id : id});
|
||||||
|
// Add a product to the selected website.
|
||||||
|
user.getSelectedWebsite().addProduct(product);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const check = ({checkFunction, callback}) => {
|
||||||
|
|
||||||
|
let checkValue = checkFunction();
|
||||||
|
//if check value is false
|
||||||
|
if(checkValue == '')
|
||||||
{
|
{
|
||||||
data.addUser(id);
|
return callback();
|
||||||
user = data.getUser(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//add the website with the company name
|
return checkValue;
|
||||||
user.addWebsite(new Website(companyName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkMediaExist = () => {
|
||||||
|
if(input['media'] == undefined){
|
||||||
|
return [
|
||||||
|
`A media should be attached with the message`,
|
||||||
|
`Please attach an image or file with the caption being the command`
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkSelectedWebsiteExist= () => {
|
||||||
|
|
||||||
|
if(user.getSelectedWebsite() == null)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
`A website should be selected or created `,
|
||||||
|
`To create website, please use the following command : `,
|
||||||
|
`*wg create <company-name>*`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkSelectedProductExist = () => {
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : () => {
|
||||||
|
if(user.getSelectedWebsite().getSelectedProduct() == null)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
`A product should be created or selected`
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.setUser = (id) =>{
|
||||||
|
|
||||||
|
if(!data.isUser(id))
|
||||||
|
{
|
||||||
|
|
||||||
|
data.addUser(new User(id));
|
||||||
|
}
|
||||||
|
user = data.getUser(id)
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.setInput= (value) => {
|
||||||
|
input = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.onCreateProduct = () => {
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : () => {
|
||||||
|
//add the product
|
||||||
|
addProduct(input['id']);
|
||||||
|
|
||||||
|
let selectedId = user.getSelectedWebsite().getSelectedProduct().id;
|
||||||
|
|
||||||
|
//mesage to be sent to the user
|
||||||
|
let message = [
|
||||||
|
`The product has been created with the id : ${selectedId}` ,
|
||||||
|
//use stripIndents to strip the indentation
|
||||||
|
stripIndents`
|
||||||
|
This product has been selected.
|
||||||
|
Now you can make change to the product with the following commands :
|
||||||
|
1. wg product info
|
||||||
|
2. wg product name <product-name>
|
||||||
|
3. wg product cost <product-cost>
|
||||||
|
4. wg product desc <product-desc>
|
||||||
|
5. wg product image *with an image attached*
|
||||||
|
`
|
||||||
|
];
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.onDeleteProduct = () => {
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : () => {
|
||||||
|
|
||||||
|
if(!user.getSelectedWebsite().deleteProduct(input['id']))
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
`No product with the given id`
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
`The product has been deleted with the id : ` + input['id']
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.onSelectProduct = () => {
|
||||||
|
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : () => {
|
||||||
|
|
||||||
|
if(!user.getSelectedWebsite().selectProduct(input['id']))
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
`There was no product with the given id. Use the following command to get the list of all products`,
|
||||||
|
`wg product all`
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
`The product has been selected with the id : ${user.getSelectedWebsite().getSelectedProduct().id}` ,
|
||||||
|
stripIndents`
|
||||||
|
This product has been selected.
|
||||||
|
Now you can make change to the product with the following commands :
|
||||||
|
1. wg product info
|
||||||
|
2. wg product name <product-name>
|
||||||
|
3. wg product cost <product-cost>
|
||||||
|
4. wg product desc <product-desc>
|
||||||
|
5. wg product image *with an image attached*
|
||||||
|
`
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.onGetAllProducts = () => {
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : () => {
|
||||||
|
let message = [
|
||||||
|
'Your website has following products: '
|
||||||
|
];
|
||||||
|
|
||||||
|
for(let p of user.getSelectedWebsite().getAllProduct())
|
||||||
|
{
|
||||||
|
let m = 'Product id: ' + p.id + '\nProduct Name : ' + p.name + '\nProduct description : '+ p.desc + '\nProduct Cost: ' + p.cost + '\nProduct Image : ';
|
||||||
|
message.push(m);
|
||||||
|
message.push(p.image);
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.onGetProductInfo = () => {
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedProductExist,
|
||||||
|
callback : () => {
|
||||||
|
let selected_product = user.getSelectedWebsite().getSelectedProduct();
|
||||||
|
return [
|
||||||
|
stripIndents`
|
||||||
|
Product id: ${selected_product.id}
|
||||||
|
Product Name : ${selected_product.name}
|
||||||
|
Product description : ${selected_product.desc }
|
||||||
|
Product Cost: ${selected_product.cost}
|
||||||
|
Product Image :`,
|
||||||
|
selected_product.image
|
||||||
|
];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.onSetProductName = () => {
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedProductExist,
|
||||||
|
callback : () => {
|
||||||
|
let selected_product = user.getSelectedWebsite().getSelectedProduct();
|
||||||
|
selected_product.setName(input['product-name']);
|
||||||
|
return [
|
||||||
|
'The product name has been set to '+ selected_product.name
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.onSetProductCost = () => {
|
||||||
|
return check ({
|
||||||
|
checkFunction : checkSelectedProductExist,
|
||||||
|
callback : () => {
|
||||||
|
let selected_product = user.getSelectedWebsite().getSelectedProduct();
|
||||||
|
selected_product.setCost(input['product-cost']);
|
||||||
|
return[
|
||||||
|
'The product cost has been set to '+ selected_product.cost
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.onSetProductDesc = () => {
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedProductExist,
|
||||||
|
callback : () => {
|
||||||
|
let selected_product = user.getSelectedWebsite().getSelectedProduct();
|
||||||
|
selected_product.setDesc(input['product-desc']);
|
||||||
|
let message = [
|
||||||
|
'The product desc has been set to '+ selected_product.desc
|
||||||
|
];
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.onSetProductImage = () => {
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedProductExist,
|
||||||
|
callback : () => {
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkMediaExist,
|
||||||
|
callback : async () => {
|
||||||
|
|
||||||
|
let selected_product = user.getSelectedWebsite().getSelectedProduct();
|
||||||
|
selected_product.setImage(input['media']);
|
||||||
|
//filename to be set
|
||||||
|
let filename = `${user.id.slice(3,10)}${user.getSelectedWebsite().companyName}${selected_product.id}`;
|
||||||
|
//url for the image that are saved
|
||||||
|
selected_product.imageUrl = await saveImage(input['media'], filename);
|
||||||
|
|
||||||
|
let message = [
|
||||||
|
'The product image has been set to the following image',
|
||||||
|
selected_product.image
|
||||||
|
];
|
||||||
|
|
||||||
|
return message;
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A help function
|
||||||
|
* @param {void} nothing
|
||||||
|
* @return {help_signal} details on how to use the website
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports.help = () =>
|
||||||
|
{
|
||||||
|
let help_signal = [
|
||||||
|
`NOTE : text between '<>' are replaceable.`,
|
||||||
|
`NOTE : Sentences needs to be between qoutes. For Example "I am a bot" `,
|
||||||
|
`*wg create <company_name> Create a website with the given company_name*`,
|
||||||
|
`*wg website select <company_name>* Selects a website if exists`,
|
||||||
|
`*wg website firstname <firstName>* Sets the firstname`,
|
||||||
|
`*wg website lastname <lastName>* Sets the firstname`,
|
||||||
|
`*wg website logo (with an image attached)* Sets the logo`,
|
||||||
|
`*wg website banner (with an image attached)* Sets the banner`,
|
||||||
|
`*wg website desc <description>* Sets the description`,
|
||||||
|
`*wg website email <email>* Sets the email`,
|
||||||
|
`*wg website finished* Completes and creates the website`,
|
||||||
|
`*wg product new <id>* Creates a new product with an id`,
|
||||||
|
`*wg product select <id>* Selects a product with a given id`,
|
||||||
|
`*wg product all* Shows all the products`,
|
||||||
|
`*wg product info* Shows the information of the selected product`,
|
||||||
|
`*wg product name <name>* Sets the name of the product`,
|
||||||
|
`*wg product desc <description>* Sets the description of the product`,
|
||||||
|
`*wg product cost <cost>* Sets the cost of the product`,
|
||||||
|
`*wg product image (with an image attached)* Sets the image of the product`,
|
||||||
|
];
|
||||||
|
|
||||||
|
return help_signal;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.onSelectWebsite = () => {
|
||||||
|
|
||||||
|
if(user.isWebsite(input['company_name']))
|
||||||
|
{
|
||||||
|
user.selectWebsite(input['company_name']);
|
||||||
|
return [`Website with the company name *${user.getSelectedWebsite().companyName}* is selected`]
|
||||||
|
}
|
||||||
|
|
||||||
|
return [`No website with the company name *${input['company_name']}* has been selected`];
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wg create
|
||||||
|
* @param {string} input of the company name
|
||||||
|
* @return {void} gives information on how to add details to website
|
||||||
|
*/
|
||||||
|
module.exports.onCreateWebsite = () =>
|
||||||
|
{
|
||||||
|
user.addWebsite(new Website(input['company_name']));
|
||||||
|
|
||||||
|
return [
|
||||||
|
`A website with the company name *${user.getSelectedWebsite().companyName}* is created`,
|
||||||
|
stripIndents`
|
||||||
|
wg website firstname *<First_Name>*
|
||||||
|
wg website lastname *<Last_Name>*
|
||||||
|
wg website logo *with an image attached*
|
||||||
|
wg website banner *with an image attached*
|
||||||
|
wg website desc *<Description>*
|
||||||
|
wg website email *<Email>*
|
||||||
|
For adding information use *wg website <firstname>*`
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.onGetInfo = () => {
|
||||||
|
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : () => {
|
||||||
|
|
||||||
|
let website = user.getSelectedWebsite();
|
||||||
|
return [
|
||||||
|
stripIndents`
|
||||||
|
First Name : ${website.firstName}
|
||||||
|
Last Name : ${website.lastName}
|
||||||
|
Company Name (id) : ${website.companyName }
|
||||||
|
Description : ${website.desc}
|
||||||
|
Email : ${website.email}
|
||||||
|
Banner :`,
|
||||||
|
website.banner,
|
||||||
|
`Logo :`,
|
||||||
|
website.logo
|
||||||
|
];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wg website firstname
|
||||||
|
* @param {string} input of the firstname for website
|
||||||
|
* @return {void} informs you that first name has been added
|
||||||
|
*/
|
||||||
|
module.exports.onSetFirstName = () =>
|
||||||
|
{
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : () => {
|
||||||
|
|
||||||
|
user.getSelectedWebsite().firstName = input['firstName'];
|
||||||
|
|
||||||
|
return [`First name has been set to ${user.getSelectedWebsite().firstName}`];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wg website lastname
|
||||||
|
* @param {string} input of the last name for website
|
||||||
|
* @return {void} informs you that last name has been added
|
||||||
|
*/
|
||||||
|
module.exports.onSetLastName = () =>
|
||||||
|
{
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : () => {
|
||||||
|
|
||||||
|
user.getSelectedWebsite().lastName = input['lastName'];
|
||||||
|
|
||||||
|
return [`Last name has been set to ${user.getSelectedWebsite().lastName}`];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wg website logo
|
||||||
|
* @param {string} input of the logo URL for website
|
||||||
|
* @return {void} informs you that logo URL has been added
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports.onSetLogo = () =>
|
||||||
|
{
|
||||||
|
return check({
|
||||||
|
//check if website exist
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
return check({
|
||||||
|
//check if media exist
|
||||||
|
checkFunction: checkMediaExist,
|
||||||
|
callback : async () => {
|
||||||
|
|
||||||
|
user.getSelectedWebsite().logo = input['media'];
|
||||||
|
user.getSelectedWebsite().logoUrl = await saveImage(input['media'], `${user.id.slice(3,10)}${user.getSelectedWebsite().companyName}logo`);
|
||||||
|
|
||||||
|
return [
|
||||||
|
`Logo has been set to the following logo`,
|
||||||
|
user.getSelectedWebsite().logo
|
||||||
|
];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wg website banner
|
||||||
|
* @param {string} input of the banner URL for website
|
||||||
|
* @return {void} informs you that banner URL has been added
|
||||||
|
*/
|
||||||
|
module.exports.onSetBanner = () =>
|
||||||
|
{
|
||||||
|
return check({
|
||||||
|
//check if website exist
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : () => {
|
||||||
|
//check if media exist
|
||||||
|
return check({
|
||||||
|
checkFunction : checkMediaExist,
|
||||||
|
callback : async () => {
|
||||||
|
|
||||||
|
user.getSelectedWebsite().banner = input['media'];
|
||||||
|
user.getSelectedWebsite().bannerUrl = await saveImage(input['media'], `${user.id.slice(3,10)}${user.getSelectedWebsite().companyName}banner`);
|
||||||
|
|
||||||
|
return [
|
||||||
|
`Banner has been set to the following banner`,
|
||||||
|
user.getSelectedWebsite().banner
|
||||||
|
];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wg website description
|
||||||
|
* @param {string} input of the company description for website
|
||||||
|
* @return {void} informs you that description has been added
|
||||||
|
*/
|
||||||
|
module.exports.onSetDesc = (descriptiondata) =>
|
||||||
|
{
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : () => {
|
||||||
|
|
||||||
|
user.getSelectedWebsite().desc = input['desc'];
|
||||||
|
return [`Description has been set to ${user.getSelectedWebsite().desc}`];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wg website email
|
||||||
|
* @param {string} input of the email for website
|
||||||
|
* @return {void} informs you that email has been added
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.onSetEmail = () =>
|
||||||
|
{
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : () => {
|
||||||
|
|
||||||
|
user.getSelectedWebsite().email = input['email'];
|
||||||
|
return [`Email has been set to ${user.getSelectedWebsite().email}`];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.onWebsiteFinished = () => {
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : async () => {
|
||||||
|
//get json from the website
|
||||||
|
let json = user.getSelectedWebsite().toJson();
|
||||||
|
//creates a promise
|
||||||
|
//resolve and reject value is going to be returned
|
||||||
|
//resolve value = message to be sent
|
||||||
|
let res = new Promise( (resolve, reject) => {
|
||||||
|
request({
|
||||||
|
url: process.argv[2]+"/generate",
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json", // <--Very important!!!
|
||||||
|
},
|
||||||
|
body: json
|
||||||
|
}, (error, response, body) => {
|
||||||
|
//send reject value in promise if error exist
|
||||||
|
if(error)
|
||||||
|
{
|
||||||
|
return reject(error);
|
||||||
|
}
|
||||||
|
// messsage to be sent
|
||||||
|
let returnStatement = [
|
||||||
|
`${process.argv[2]}/pages/${JSON.parse(response.body).directory}`,
|
||||||
|
`*Website ID:* ${JSON.parse(response.body).directory}`,
|
||||||
|
`*Important to remember the ID*`
|
||||||
|
];
|
||||||
|
//send resolve value id
|
||||||
|
resolve(returnStatement);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//waits for request to be completed
|
||||||
|
let msg = await res;
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.onDeployWebsite = () => {
|
||||||
|
return check({
|
||||||
|
checkFunction: checkSelectedWebsiteExist,
|
||||||
|
callback : async () => {
|
||||||
|
let res = new Promise( (resolve, reject) => {
|
||||||
|
request({
|
||||||
|
url: process.argv[2]+"/ipfsdeploy?id="+ user.getSelectedWebsite().companyName,
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json", // <--Very important!!!
|
||||||
|
}
|
||||||
|
}, function (error, response, body){
|
||||||
|
// reject error in promise
|
||||||
|
if(error)
|
||||||
|
{
|
||||||
|
return reject(error);
|
||||||
|
}
|
||||||
|
// messsage to be sent
|
||||||
|
let returnStatement = [
|
||||||
|
`https://ipfs.io/ipfs/${JSON.parse(response.body).data}`,
|
||||||
|
`Takes around 10-30 minutues to deploy`,
|
||||||
|
`Read more about IPFS https://ipfs.io/`
|
||||||
|
];
|
||||||
|
//send resolve value id
|
||||||
|
resolve(returnStatement);
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
let msg = await res;
|
||||||
|
return msg;
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,47 +1,41 @@
|
|||||||
|
|
||||||
# Commands available for user interaction
|
# Commands available for user interaction
|
||||||
|
|
||||||
*wg* -> Command wg help to get the avaialabe instructions
|
`wg` -> Command wg help to get the avaialabe instructions.
|
||||||
*wg help* -> The following are the available commands:
|
`wg help` -> All the commands will be made be displayed to the user.
|
||||||
*wg create <company name> -> creates a website without details
|
`wg website <company name>` -> if a website exists with the same **company name**, then that website is selected, else it creates a new website.
|
||||||
|
|
||||||
# Note:
|
### Note:
|
||||||
After the user uses *wg create <company name>*. The bot should instruct the user to enter the rest of the details.
|
After the user uses `wg create <company name>`. The bot should instruct the user to enter the rest of the details.
|
||||||
To see the details to be entered, please check *website.js* under models folder.
|
To see the details to be entered, please check [website.js](https://github.com/HWTechClub/Custom-Static-Website-Generator/blob/master/whatsapp-web.js/src/models/website.js) under models folder.
|
||||||
|
|
||||||
The commands should follow the rules below :
|
The commands should follow the rules below :
|
||||||
*wg website firstName*
|
`wg website firstName`, `wg website lastName`, etc..
|
||||||
*wg website lastName*
|
|
||||||
...etc
|
|
||||||
|
|
||||||
|
### Following commands only works when a website is created
|
||||||
|
|
||||||
|
`wg product all` -> shows all the products that are created.
|
||||||
|
`wg product new` -> creates a new product with generated Id.
|
||||||
|
`wg product <id>` -> if the id exists, the product with *id* is selected, else, create a new product with the id given.
|
||||||
|
|
||||||
|
### NOTE :
|
||||||
# Following commands only works when a website is created
|
|
||||||
|
|
||||||
*wg product all* -> shows all the products that are created
|
|
||||||
*wg product new* -> creates a new product with generated Id
|
|
||||||
*wg product <id>* -> if the id exists, the product with “id“ is selected, else, create a new product with the id given
|
|
||||||
|
|
||||||
# NOTE :
|
|
||||||
User should be given feedback on their commands. For example:
|
User should be given feedback on their commands. For example:
|
||||||
If a user created a product, the bot should reply, "a product has been created with the id : <id>"
|
If a user created a product, the bot should reply, *a product has been created with the id : <id>*.
|
||||||
If a user created a product without a website, the bot should handle the error and reply, "A website should be selected or created before creating a product"
|
If a user created a product without a website, the bot should handle the error and reply, *A website should be selected or created before creating a product*.
|
||||||
|
|
||||||
# Following command only works if a product is selected
|
### Following command only works if a product is selected
|
||||||
*wg product info* -> shows the information about the product. Ie name, cost, description, image
|
`wg product info` -> shows the information about the product. Ie name, cost, description, image.
|
||||||
*wg product name* <product-name> -> set the name of the product
|
`wg product name <product-name>` -> set the name of the product.
|
||||||
*wg product cost* <product-cost> -> set the cost of the product
|
`wg product cost <product-cost>` -> set the cost of the product.
|
||||||
*wg product desc* <product-desc> -> set the description of the product
|
`wg product desc <product-desc>` -> set the description of the product.
|
||||||
*wg product image* <product-image> -> sets the image of the product. The caption of the image should be the command.
|
`wg product image <product-image>` -> sets the image of the product. The caption of the image should be the command.
|
||||||
*wg finished* -> creates the website and gives a link to the website maker
|
|
||||||
|
|
||||||
# delete
|
|
||||||
Users should be able to delete products and website
|
|
||||||
*wg delete product <id>*
|
|
||||||
*wg delete website <company name>*
|
|
||||||
|
|
||||||
|
### Create the website
|
||||||
|
`wg website finished` -> creates the website and gives a link to the website maker.
|
||||||
|
|
||||||
|
# Delete
|
||||||
|
Users should be able to delete products and website.
|
||||||
|
`wg delete product <id>`, `wg delete website <company name>`
|
||||||
|
|
||||||
# Note:
|
# Note:
|
||||||
If you think these commands are not enough, please add them in a seperate section with a clear defination.
|
If you think these commands are not enough, please add them in a seperate section with a clear defination.
|
||||||
@@ -1,10 +1,160 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
class Command{
|
class Command{
|
||||||
|
|
||||||
|
/**
|
||||||
constructor({command,callback}){
|
*
|
||||||
|
* @param {{string, function(),boolean}} param0
|
||||||
|
*/
|
||||||
|
constructor({command,callback, requireMedia = false}){
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.requireMedia = requireMedia;
|
||||||
|
this.requireInput = false;
|
||||||
|
this.inputPos = [];
|
||||||
|
this._requireInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a message is equal to the command.
|
||||||
|
* @param {string} message
|
||||||
|
*/
|
||||||
|
equals(message){
|
||||||
|
let msg = message.trim();
|
||||||
|
|
||||||
|
//check if the command is exactly equals to the msg
|
||||||
|
//if mathces then return true
|
||||||
|
//else if we check if the command requires an input
|
||||||
|
//if not, then we return false
|
||||||
|
if(this.command == msg){
|
||||||
|
return true
|
||||||
|
}else if(this.requireInput){
|
||||||
|
//the command requires input
|
||||||
|
|
||||||
|
|
||||||
|
let splitCommand = this.command.split(' ');
|
||||||
|
let splitMsg = this._getSplitMessage(message);
|
||||||
|
|
||||||
|
|
||||||
|
//check the number of words both has
|
||||||
|
//if not same then return false
|
||||||
|
//else iterate through all the words
|
||||||
|
|
||||||
|
|
||||||
|
if(splitCommand.length == splitMsg.length)
|
||||||
|
{
|
||||||
|
for(let i = 0; i < splitMsg.length; i++)
|
||||||
|
{
|
||||||
|
//if words matches then continue
|
||||||
|
//if the word is a input then continue
|
||||||
|
//else return false
|
||||||
|
if(splitMsg[i] == splitCommand[i]){
|
||||||
|
continue;
|
||||||
|
}else if(splitCommand[i].match(/[<>]/g) != null){
|
||||||
|
continue;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// all the words are matched to each other or to an input field
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//the message is not the same as the command
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only used in class
|
||||||
|
*
|
||||||
|
* This determines if the command requires input
|
||||||
|
* if the command has <inputName> in the string
|
||||||
|
* then the command requires input
|
||||||
|
*
|
||||||
|
* else if the command requires media
|
||||||
|
* then the command requires input
|
||||||
|
*/
|
||||||
|
_requireInput(){
|
||||||
|
if(this.requireMedia)
|
||||||
|
{
|
||||||
|
this.requireInput = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let msg = this.command;
|
||||||
|
|
||||||
|
let matched = msg.match(/[<>]/g);
|
||||||
|
|
||||||
|
this.requireInput = matched != null && matched.length > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns an array of string or MessageMedia representing the inputs of the command
|
||||||
|
* @param {import("whatsapp-web.js").Message} message
|
||||||
|
*/
|
||||||
|
async getInput(message){
|
||||||
|
|
||||||
|
if(this.requireMedia){
|
||||||
|
|
||||||
|
return await this._getInputMedia(message);
|
||||||
|
}else{
|
||||||
|
|
||||||
|
return this._getInputMessage(message.body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an object with string input from a message
|
||||||
|
* The string is mapped to the command variable
|
||||||
|
* @param {string} msgString
|
||||||
|
*/
|
||||||
|
_getInputMessage(msgString){
|
||||||
|
|
||||||
|
let input = {};
|
||||||
|
let splitMsg = this._getSplitMessage(msgString);
|
||||||
|
let splitCommand = this.command.split(' ');
|
||||||
|
for(let i = 0; i < splitMsg.length; i++){
|
||||||
|
if(splitCommand[i].startsWith('<')){
|
||||||
|
let key = splitCommand[i].slice(1, splitCommand[i].length-1);
|
||||||
|
input[key] = splitMsg[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits the message into an array of words
|
||||||
|
* Splits the message by space and ""
|
||||||
|
* @param {string} msg
|
||||||
|
*/
|
||||||
|
_getSplitMessage(msg){
|
||||||
|
let split = msg.split(/["]/g);
|
||||||
|
if(split.length > 1)
|
||||||
|
{
|
||||||
|
let splitMsg = split[0].trim().split(' ');
|
||||||
|
let inputs = split.slice(1).filter( el => el.trim() == "" ? null : el);
|
||||||
|
splitMsg = splitMsg.concat(inputs);
|
||||||
|
return splitMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
return msg.split(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an object with a meesageMedia mapped to 'media'
|
||||||
|
* @param {import("whatsapp-web.js").Message} message
|
||||||
|
*/
|
||||||
|
async _getInputMedia(message){
|
||||||
|
let input = {};
|
||||||
|
if(message.hasMedia){
|
||||||
|
let media = await message.downloadMedia();
|
||||||
|
input['media'] = media;
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.Command = Command;
|
module.exports.Command = Command;
|
||||||
|
|||||||
@@ -1,22 +1,18 @@
|
|||||||
|
const { Entity } = require("./entity");
|
||||||
const { User } = require("./user");
|
const { User } = require("./user");
|
||||||
const { Website } = require("./website");
|
|
||||||
|
|
||||||
module.exports.data = new StructuredData();
|
|
||||||
|
|
||||||
class StructuredData {
|
class StructuredData {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.data={};
|
this.entity = new Entity();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
addUser(id){
|
* Adds a user
|
||||||
if(this.data[id] != undefined)
|
* @param {User} user
|
||||||
{
|
*/
|
||||||
this.data[id] = new User(id);
|
addUser(user){
|
||||||
return true
|
return this.entity.addData(user.id, user);
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,22 +21,37 @@ class StructuredData {
|
|||||||
* @returns {User}
|
* @returns {User}
|
||||||
*/
|
*/
|
||||||
getUser(id){
|
getUser(id){
|
||||||
return this.data[id];
|
return this.entity.getData(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the user with a specific id
|
||||||
|
* @param {string} id
|
||||||
|
*/
|
||||||
deleteUser(id){
|
deleteUser(id){
|
||||||
if(this.data[id] != undefined)
|
return this.entity.deleteData(id)
|
||||||
{
|
}
|
||||||
return delete this.data[id];
|
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Check if a user with the given id exists
|
||||||
|
* @param {string} id
|
||||||
|
*/
|
||||||
|
isUser(id){
|
||||||
|
return this.entity.isData(id);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
/**
|
||||||
|
* Clears all the data stored
|
||||||
|
*/
|
||||||
|
clearData(){
|
||||||
|
this.entity.clearData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.data = new StructuredData();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
data structured:
|
data structured:
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
80
whatsapp-web.js/src/models/entity.js
Normal file
80
whatsapp-web.js/src/models/entity.js
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
|
||||||
|
class Entity {
|
||||||
|
|
||||||
|
constructor(){
|
||||||
|
this.data = new Map();
|
||||||
|
this.selectedData = null;
|
||||||
|
this.count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
addData(key ,value){
|
||||||
|
if(!this.isData(key)){
|
||||||
|
this.data.set(key, value);
|
||||||
|
this.selectedData = key;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if key exists
|
||||||
|
* @param {string} key
|
||||||
|
*/
|
||||||
|
isData(key){
|
||||||
|
return this.data.has(key) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteData(key){
|
||||||
|
if(this.isData(key)){
|
||||||
|
this.data.delete(key);
|
||||||
|
if(this.selectedData == key){
|
||||||
|
this.selectedData = null;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearData(){
|
||||||
|
this.selectedData = null;
|
||||||
|
this.data = new Map();
|
||||||
|
this.count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select a specific data with its key
|
||||||
|
* @param {string} key
|
||||||
|
* @returns true if a data is selected
|
||||||
|
* @returns false if data is null
|
||||||
|
*/
|
||||||
|
selectData(key){
|
||||||
|
if(this.isData(key))
|
||||||
|
{
|
||||||
|
this.selectedData = key;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} key
|
||||||
|
* @returns the value mapped to the key
|
||||||
|
*/
|
||||||
|
getData(key){
|
||||||
|
if(this.isData(key)){
|
||||||
|
return this.data.get(key);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns a map of all data
|
||||||
|
*/
|
||||||
|
getAllData(){
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.Entity = Entity;
|
||||||
@@ -1,48 +1,49 @@
|
|||||||
|
|
||||||
class Product {
|
class Product {
|
||||||
|
|
||||||
constructor({ id = '', name = '', desc = '', cost = 0, image = null }) {
|
constructor({ id = '', name = '', desc = '', cost = 0, image = null } = {}) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.desc = desc;
|
this.desc = desc;
|
||||||
this.cost = cost;
|
this.cost = cost;
|
||||||
this.image = image;
|
this.image = image;
|
||||||
|
this.imageUrl = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
getId(){
|
/**
|
||||||
return this.id;
|
*
|
||||||
|
* @param {Number} id
|
||||||
|
*/
|
||||||
|
setId(id){
|
||||||
|
return this.id = id;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {String} name
|
||||||
|
*/
|
||||||
setName(name){
|
setName(name){
|
||||||
this.name = name;
|
return this.name = name;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
getName(){
|
*
|
||||||
return this.name;
|
* @param {String} description
|
||||||
|
*/
|
||||||
|
setDesc(description){
|
||||||
|
return this.desc = description;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
setDesc(desc){
|
*
|
||||||
this.desc = desc;
|
* @param {Number} cost
|
||||||
}
|
*/
|
||||||
|
|
||||||
getDesc(){
|
|
||||||
return this.desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
setCost(cost){
|
setCost(cost){
|
||||||
this.cost = cost;
|
return this.cost = cost;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
getCost(){
|
*
|
||||||
return this.cost;
|
* @param {String} image
|
||||||
}
|
*/
|
||||||
|
|
||||||
setImage(image){
|
setImage(image){
|
||||||
this.imageUrl = image;
|
return this.image = image;
|
||||||
}
|
|
||||||
|
|
||||||
getImage(){
|
|
||||||
return this.imageUrl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
|
|
||||||
|
const { Entity } = require('./entity');
|
||||||
const {Website} = require('./website');
|
const {Website} = require('./website');
|
||||||
|
|
||||||
class User{
|
class User{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} id
|
||||||
|
*/
|
||||||
constructor(id){
|
constructor(id){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
//uses key value pair to store website
|
this.websites = new Entity();
|
||||||
//key is the companyName of the website
|
|
||||||
//value is the website itself
|
|
||||||
this.websites = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,26 +18,31 @@ class User{
|
|||||||
* @param {Website} website
|
* @param {Website} website
|
||||||
*/
|
*/
|
||||||
addWebsite(website){
|
addWebsite(website){
|
||||||
if(this.websites[website.companyName] != undefined)
|
return this.websites.addData(website.companyName, website);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}else{
|
|
||||||
this.websites[website.companyName] = website;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteWebsite(companyName){
|
deleteWebsite(companyName){
|
||||||
if(this.websites[companyName] != undefined)
|
return this.websites.deleteData(companyName);
|
||||||
{
|
|
||||||
return delete this.websites[companyName];
|
|
||||||
}else{
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getWebsite(companyName){
|
getWebsite(companyName){
|
||||||
return this.websites[companyName];
|
return this.websites.getData(companyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
isWebsite(companyName){
|
||||||
|
return this.websites.isData(companyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectWebsite(companyName)
|
||||||
|
{
|
||||||
|
return this.websites.selectData(companyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Website}
|
||||||
|
*/
|
||||||
|
getSelectedWebsite(){
|
||||||
|
return this.getWebsite(this.websites.selectedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
const { Entity } = require('./entity');
|
||||||
const {Product} = require('./product');
|
const {Product} = require('./product');
|
||||||
|
|
||||||
class Website {
|
class Website {
|
||||||
@@ -9,6 +10,8 @@ class Website {
|
|||||||
this.firstName = '';
|
this.firstName = '';
|
||||||
this.lastName = '';
|
this.lastName = '';
|
||||||
this.companyName = companyName;
|
this.companyName = companyName;
|
||||||
|
this.logo = '';
|
||||||
|
this.banner = '';
|
||||||
this.logoUrl = '';
|
this.logoUrl = '';
|
||||||
this.bannerUrl = '';
|
this.bannerUrl = '';
|
||||||
this.desc = '';
|
this.desc = '';
|
||||||
@@ -16,7 +19,7 @@ class Website {
|
|||||||
//uses key value pair to store product
|
//uses key value pair to store product
|
||||||
//key is the productId of the product
|
//key is the productId of the product
|
||||||
//value is the product itself
|
//value is the product itself
|
||||||
this.products = {};
|
this.products = new Entity();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,13 +27,7 @@ class Website {
|
|||||||
* @param {Product} product
|
* @param {Product} product
|
||||||
*/
|
*/
|
||||||
addProduct(product){
|
addProduct(product){
|
||||||
if(this.products[product.id] == undefined)
|
return this.products.addData(product.id, product);
|
||||||
{
|
|
||||||
this.products[product.id] = product;
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,7 +36,15 @@ class Website {
|
|||||||
* @returns {Product}
|
* @returns {Product}
|
||||||
*/
|
*/
|
||||||
getProduct(productId){
|
getProduct(productId){
|
||||||
return this.products[productId];
|
return this.products.getData(productId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* returns all the products in the website
|
||||||
|
*/
|
||||||
|
getAllProduct(){
|
||||||
|
return this.products.getAllData().values();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,12 +52,42 @@ class Website {
|
|||||||
* @param {string} productId
|
* @param {string} productId
|
||||||
*/
|
*/
|
||||||
deleteProduct(productId){
|
deleteProduct(productId){
|
||||||
if(this.products[productId] != undefined)
|
|
||||||
{
|
|
||||||
return delete this.products[productId];
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return this.products.deleteData(productId);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectProduct(productId){
|
||||||
|
return this.products.selectData(productId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Product}
|
||||||
|
*/
|
||||||
|
getSelectedProduct()
|
||||||
|
{
|
||||||
|
return this.getProduct(this.products.selectedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(){
|
||||||
|
let j = {};
|
||||||
|
j["firstName"] = this.firstName;
|
||||||
|
j["lastName"] = this.lastName;
|
||||||
|
j["companyName"] = this.companyName;
|
||||||
|
j["logoUrl"] = this.logoUrl;
|
||||||
|
j["bannerUrl"] = this.bannerUrl;
|
||||||
|
j["email"] = this.email;
|
||||||
|
j["description"] = this.desc;
|
||||||
|
j["template"] = 'Colo_Shop';
|
||||||
|
|
||||||
|
let csv = 'product id,product name,description,cost,product image url\n';
|
||||||
|
for (let prod of this.products.getAllData().values())
|
||||||
|
{
|
||||||
|
let m = [prod.id, prod.name, prod.desc, prod.cost, prod.imageUrl].join(',');
|
||||||
|
csv += `${m}\n`;
|
||||||
|
}
|
||||||
|
j['csv'] = csv;
|
||||||
|
|
||||||
|
return JSON.stringify(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
|
|
||||||
const { Command } = require("../models/commands");
|
const { Command } = require("../models/commands");
|
||||||
const logic = require("../businessLogic/logic");
|
const logic = require("../businessLogic/logic");
|
||||||
|
const { Website } = require("../models/website");
|
||||||
|
const { Product } = require('../models/product');
|
||||||
|
|
||||||
///////////
|
|
||||||
//add the commands here
|
|
||||||
///////////
|
//commands and the corresponding function to be executed
|
||||||
|
//are input in the array
|
||||||
const commands = [
|
const commands = [
|
||||||
new Command({
|
new Command({
|
||||||
//User command
|
//User command
|
||||||
command: 'wg',
|
command: 'wg',
|
||||||
|
|
||||||
//function to be executed
|
//function to be executed
|
||||||
callback : () => {
|
callback : (input) => {
|
||||||
|
|
||||||
logic.onWG();
|
logic.onWG();
|
||||||
//mesage to be sent to the user
|
//mesage to be sent to the user
|
||||||
let message = [
|
let message = [
|
||||||
@@ -23,28 +25,222 @@ const commands = [
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: `wg product new <id>`,
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onCreateProduct
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: `wg product delete <id>`,
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onDeleteProduct
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: `wg product select <id>`,
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSelectProduct
|
||||||
|
}),
|
||||||
|
|
||||||
|
|
||||||
|
//gives user information on how to create website
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: 'wg help',
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.help
|
||||||
|
}),
|
||||||
|
|
||||||
|
//helps user to create a website. The first step.
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: 'wg create <company_name>',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onCreateWebsite
|
||||||
|
}),
|
||||||
|
//Inputs user's first name for website
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: 'wg website select <company_name>',
|
||||||
|
callback : logic.onSelectWebsite
|
||||||
|
}),
|
||||||
|
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
|
||||||
|
command: 'wg website firstname <firstName>',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetFirstName
|
||||||
|
}),
|
||||||
|
|
||||||
|
|
||||||
|
//inputs user last name in website
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
|
||||||
|
command: 'wg website lastname <lastName>',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetLastName
|
||||||
|
}),
|
||||||
|
|
||||||
|
//inputs the logo of the company to website using url of logo
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: 'wg website logo',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetLogo,
|
||||||
|
requireMedia : true
|
||||||
|
}),
|
||||||
|
|
||||||
|
|
||||||
|
//inputs the banner for the company to website using url of banner
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
|
||||||
|
command: 'wg website banner',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetBanner,
|
||||||
|
|
||||||
|
requireMedia: true,
|
||||||
|
}),
|
||||||
|
|
||||||
|
//inputs the description of the company to be seen in the website
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
|
||||||
|
command: 'wg website desc <desc>',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetDesc
|
||||||
|
}),
|
||||||
|
|
||||||
|
//inputs the email of the company for contacting.
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
|
||||||
|
command: 'wg website email <email>',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetEmail
|
||||||
|
}),
|
||||||
|
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
|
||||||
|
command: 'wg website info',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onGetInfo
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
|
||||||
|
command: 'wg website finished',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onWebsiteFinished
|
||||||
|
}),
|
||||||
|
//gives user information on how to create website
|
||||||
|
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: `wg product all`,
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onGetAllProducts
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: `wg product info`,
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onGetProductInfo
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: `wg product name <product-name>`,
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetProductName
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: `wg product cost <product-cost>`,
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetProductCost
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: 'wg product desc <product-desc>',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetProductDesc
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: 'wg product image',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetProductImage,
|
||||||
|
|
||||||
|
requireMedia: true
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: 'wg deploy ipfs',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onDeployWebsite,
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
module.exports= onMessage = async (message, client) => {
|
||||||
const onMessage = (message, client) => {
|
|
||||||
|
|
||||||
let command = null;
|
let command = null;
|
||||||
|
|
||||||
//if the message start with wg then proceed
|
//if the message start with wg then proceed
|
||||||
if(message.body.startsWith("wg"))
|
if(message.body.startsWith("wg"))
|
||||||
{
|
{
|
||||||
|
//loop through all the commands
|
||||||
for (let c of commands){
|
for (let c of commands){
|
||||||
if(c.command == message.body)
|
//check if the message sent is equal to the commands
|
||||||
|
//if the message matches a command,
|
||||||
|
//then save the command in the command variable
|
||||||
|
if(c.equals(message.body))
|
||||||
{
|
{
|
||||||
command = c;
|
command = c;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if the command is not null, implies, the message sent is a valid command
|
||||||
if(command != null){
|
if(command != null){
|
||||||
let messageToBeSent = command.callback();
|
let input = {};
|
||||||
|
//check if the command requires input
|
||||||
|
if(command.requireInput){
|
||||||
|
input = await command.getInput(message);
|
||||||
|
}
|
||||||
|
//determine the user
|
||||||
|
logic.setUser(message.id.remote);
|
||||||
|
//determine the input
|
||||||
|
logic.setInput(input);
|
||||||
|
//call callback function in the command
|
||||||
|
//await is used, so that if a command is an async function
|
||||||
|
//the program will wait until it is finished
|
||||||
|
//the callback returns a message to be sent to the user
|
||||||
|
let messageToBeSent = await command.callback();
|
||||||
|
|
||||||
|
// send the message to the user
|
||||||
for (let msg of messageToBeSent)
|
for (let msg of messageToBeSent)
|
||||||
{
|
{
|
||||||
client.sendMessage(message.from, msg, new Object());
|
client.sendMessage(message.from, msg, new Object());
|
||||||
@@ -54,6 +250,7 @@ const onMessage = (message, client) => {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.onMessage = onMessage;
|
|
||||||
|
|
||||||
|
|
||||||
//export default onMessage;
|
//export default onMessage;
|
||||||
196
whatsapp-web.js/test/test_command.js
Normal file
196
whatsapp-web.js/test/test_command.js
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
const { Command } = require('../src/models/commands');
|
||||||
|
|
||||||
|
const expect = require('chai').expect;
|
||||||
|
|
||||||
|
describe('Command', () => {
|
||||||
|
|
||||||
|
it('Test : requireInput() without input', () => {
|
||||||
|
let a = new Command({
|
||||||
|
command: "wg create",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(a.requireInput).to.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test : requireInput() with input', () => {
|
||||||
|
let a = new Command({
|
||||||
|
command: "wg create <id>",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(a.requireInput).to.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test : requireInput() with 2 inputs', () => {
|
||||||
|
let a = new Command({
|
||||||
|
command: "wg create <id> <name>",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(a.requireInput).to.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test : equals() without input', () => {
|
||||||
|
|
||||||
|
let message = 'wg website';
|
||||||
|
|
||||||
|
let a = new Command({
|
||||||
|
command: "wg create <id>",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let b = new Command({
|
||||||
|
command: "wg website",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let c = new Command({
|
||||||
|
command: "wg product p12",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let d = new Command({
|
||||||
|
command: "wg",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(a.equals(message)).to.false;
|
||||||
|
expect(b.equals(message)).to.true;
|
||||||
|
expect(c.equals(message)).to.false;
|
||||||
|
expect(d.equals(message)).to.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('Test : equals() with input', () => {
|
||||||
|
|
||||||
|
let message = 'wg create p12';
|
||||||
|
|
||||||
|
let a = new Command({
|
||||||
|
command: "wg create <id>",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(a.equals(message)).to.true;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test : equals() with different message', () => {
|
||||||
|
|
||||||
|
let message = 'wg website web';
|
||||||
|
|
||||||
|
let a = new Command({
|
||||||
|
command: "wg create <id>",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(a.equals(message)).to.false;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test : equals() with spelling error', () => {
|
||||||
|
|
||||||
|
let message = 'wg websit';
|
||||||
|
|
||||||
|
let b = new Command({
|
||||||
|
command: "wg website",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(b.equals(message)).to.false;
|
||||||
|
|
||||||
|
});
|
||||||
|
it('Test : equals() with extra inputs', () => {
|
||||||
|
|
||||||
|
let message = 'wg create p12 pr';
|
||||||
|
|
||||||
|
let a = new Command({
|
||||||
|
command: "wg create <id>",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
expect(a.equals(message)).to.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test : _getInputMessage() with 1 input', () => {
|
||||||
|
|
||||||
|
let message = 'wg create p12'
|
||||||
|
|
||||||
|
let a = new Command({
|
||||||
|
command: "wg create <id>",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(a._getInputMessage(message)['id']).to.equal('p12');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test : _getInputMessage() with 2 input', () => {
|
||||||
|
|
||||||
|
let message = 'wg create p12 pikachu'
|
||||||
|
|
||||||
|
let a = new Command({
|
||||||
|
command: "wg create <id> <name>",
|
||||||
|
callback: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(a._getInputMessage(message)['id']).to.equal('p12');
|
||||||
|
expect(a._getInputMessage(message)['name']).to.equal('pikachu');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test : _getSplitMessage() with a sentence', () => {
|
||||||
|
let a = new Command({command : 'wg website desc <desc>'});
|
||||||
|
let b = a._getSplitMessage(`wg website desc "Hello everynyan, how are you"`);
|
||||||
|
expect(b[0]).to.equal('wg');
|
||||||
|
expect(b[1]).to.equal('website');
|
||||||
|
expect(b[2]).to.equal('desc');
|
||||||
|
expect(b[3]).to.equal('Hello everynyan, how are you');
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Test : _getSplitMessage() with multiple sentence input', () => {
|
||||||
|
let a = new Command({command : 'wg website desc <desc>'});
|
||||||
|
let b = a._getSplitMessage(`wg website desc "Hello everynyan, how are you" "I am fine thank you"`);
|
||||||
|
expect(b[0]).to.equal('wg');
|
||||||
|
expect(b[1]).to.equal('website');
|
||||||
|
expect(b[2]).to.equal('desc');
|
||||||
|
expect(b[3]).to.equal('Hello everynyan, how are you');
|
||||||
|
expect(b[4]).to.equal('I am fine thank you');
|
||||||
|
})
|
||||||
|
it('Test : _getSplitMessage() with single word', () => {
|
||||||
|
let a = new Command({command : 'wg website desc <desc>'});
|
||||||
|
let b = a._getSplitMessage(`wg website desc Hello`);
|
||||||
|
expect(b[0]).to.equal('wg');
|
||||||
|
expect(b[1]).to.equal('website');
|
||||||
|
expect(b[2]).to.equal('desc');
|
||||||
|
expect(b[3]).to.equal('Hello');
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
117
whatsapp-web.js/test/test_entity.js
Normal file
117
whatsapp-web.js/test/test_entity.js
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
const expect = require('chai').expect;
|
||||||
|
const {data} = require('../src/models/data')
|
||||||
|
const {Entity} = require('../src/models/entity');
|
||||||
|
const { Website } = require('../src/models/website');
|
||||||
|
|
||||||
|
describe('Entity', () => {
|
||||||
|
|
||||||
|
it('Test : addData', () => {
|
||||||
|
let a = new Entity();
|
||||||
|
a.addData('hello', new Website('hello'));
|
||||||
|
|
||||||
|
expect(a.isData('hello')).to.true;
|
||||||
|
expect(a.count).to.equal(0);
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test : clearData()', () => {
|
||||||
|
let a = new Entity();
|
||||||
|
a.addData('hello world', new Website('hello world'));
|
||||||
|
a.addData('gada', new Website('gada'));
|
||||||
|
a.addData('pagol', new Website('pagol'));
|
||||||
|
|
||||||
|
a.clearData();
|
||||||
|
|
||||||
|
expect(a.count).to.equal(0);
|
||||||
|
expect(a.isData("kruta")).to.false;
|
||||||
|
expect(a.isData("hello")).to.false;
|
||||||
|
expect(a.isData('pagol')).to.false;
|
||||||
|
expect(a.isData('hello world')).to.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test: getData', () => {
|
||||||
|
let a = new Entity();
|
||||||
|
a.addData('hello world', new Website('hello world'));
|
||||||
|
a.addData('gada', new Website('gada'));
|
||||||
|
a.addData('pagol', new Website('pagol'));
|
||||||
|
|
||||||
|
expect(a.getData('hello world').companyName).to.equal('hello world');
|
||||||
|
expect(a.getData('gada').companyName).to.equal('gada');
|
||||||
|
expect(a.getData('chu chu')).to.null;
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Test: deleteData', () => {
|
||||||
|
let a = new Entity();
|
||||||
|
a.addData('hello world', new Website('hello world'));
|
||||||
|
a.addData('gada', new Website('gada'));
|
||||||
|
a.addData('pagol', new Website('pagol'));
|
||||||
|
|
||||||
|
a.deleteData('gada');
|
||||||
|
expect(a.getData('gada')).to.null;
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Test: getAllData', () => {
|
||||||
|
let a = new Entity();
|
||||||
|
a.addData('hello world', new Website('hello world'));
|
||||||
|
a.addData('gada', new Website('gada'));
|
||||||
|
a.addData('pagol', new Website('pagol'));
|
||||||
|
|
||||||
|
let websitegen = a.getAllData().values();
|
||||||
|
for(let t of websitegen)
|
||||||
|
{
|
||||||
|
console.log(t.companyName);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Test: selectData()', () => {
|
||||||
|
let a = new Entity();
|
||||||
|
a.addData('hello world', new Website('hello world'));
|
||||||
|
a.addData('gada', new Website('gada'));
|
||||||
|
a.addData('pagol', new Website('pagol'));
|
||||||
|
|
||||||
|
a.selectData('gada');
|
||||||
|
|
||||||
|
expect(a.selectedData).to.equals('gada');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test: selectedData() = false', () => {
|
||||||
|
let a = new Entity();
|
||||||
|
a.addData('hello world', new Website('hello world'));
|
||||||
|
a.addData('gada', new Website('gada'));
|
||||||
|
a.addData('pagol', new Website('pagol'));
|
||||||
|
a.selectData('tara');
|
||||||
|
expect(a.selectedData).to.equals('pagol');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test: selectedData when addData() is used', () => {
|
||||||
|
let a = new Entity();
|
||||||
|
a.addData('hello world', new Website('hello world'));
|
||||||
|
a.addData('gada', new Website('gada'));
|
||||||
|
a.addData('pagol', new Website('pagol'));
|
||||||
|
|
||||||
|
expect(a.selectedData).to.equals('pagol');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('Test : selectedData when clearData()', () => {
|
||||||
|
let a = new Entity();
|
||||||
|
a.addData('hello world', new Website('hello world'));
|
||||||
|
a.addData('gada', new Website('gada'));
|
||||||
|
a.addData('pagol', new Website('pagol'));
|
||||||
|
|
||||||
|
a.clearData();
|
||||||
|
|
||||||
|
expect(a.count).to.equal(0);
|
||||||
|
expect(a.isData("kruta")).to.false;
|
||||||
|
expect(a.isData("hello")).to.false;
|
||||||
|
expect(a.isData('pagol')).to.false;
|
||||||
|
expect(a.isData('hello world')).to.false;
|
||||||
|
expect(a.selectedData).to.null;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user