Skip to content

Commit

Permalink
Add modular listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcardeenas committed Apr 3, 2020
1 parent 9b0700d commit 83f3b79
Show file tree
Hide file tree
Showing 58 changed files with 5,288 additions and 815 deletions.
2,689 changes: 2,631 additions & 58 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sulla",
"version": "1.1.3",
"version": "2.0.0",
"description": "Javascript whatsapp framework",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -41,8 +41,10 @@
"devDependencies": {
"@types/node": "^13.9.8",
"@types/puppeteer": "^2.0.1",
"@types/sharp": "^0.24.0",
"concurrently": "^5.1.0",
"copy-webpack-plugin": "^5.1.1",
"gulp": "^4.0.2",
"husky": "^4.2.3",
"nodemon": "^2.0.2",
"prettier": "^2.0.2",
Expand All @@ -53,9 +55,11 @@
"webpack-cli": "^3.3.11"
},
"dependencies": {
"axios": "^0.19.2",
"ora": "^4.0.3",
"puppeteer": "^2.1.1",
"qrcode-terminal": "^0.12.0",
"rxjs": "^6.5.4"
"rxjs": "^6.5.4",
"sharp": "^0.25.2"
}
}
1 change: 0 additions & 1 deletion src/api/functions/send-image.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as fs from 'fs';

declare module WAPI {
// New
const sendImage: (
to: string,
imgBase64: string,
Expand Down
19 changes: 19 additions & 0 deletions src/api/functions/send-text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
declare module WAPI {
const sendSeen: (to: string) => void;
const sendMessage: (to: string, content: string) => string;
}

/**
* Sends a text message to given chat
* @param to chat id: [email protected]
* @param content text message
*/
export async function sendText(to: string, content: string) {
return await this.page.evaluate(
({ to, content }) => {
WAPI.sendSeen(to);
return WAPI.sendMessage(to, content);
},
{ to, content }
);
}
4 changes: 4 additions & 0 deletions src/api/helpers/exposed.enum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export enum ExposedFn {
OnMessage = 'onMessage',
OnAnyMessage = 'onAnyMessage',
onAck = 'onAck',
onParticipantsChanged = 'onParticipantsChanged',
onStateChanged = 'onStateChanged',
}
8 changes: 8 additions & 0 deletions src/api/model/ack-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export enum AckType {
ACK_ERROR = -1,
ACK_PENDING = 0,
ACK_SERVER = 1,
ACK_DEVICE = 2,
ACK_READ = 3,
ACK_PLAYED = 4,
}
5 changes: 5 additions & 0 deletions src/api/model/chat-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum ChatState {
TYPING = 0,
RECORDING = 1,
PAUSED = 2,
}
3 changes: 3 additions & 0 deletions src/api/model/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ export interface Chat {
presence: any;
t: number;
unreadCount: number;
ack?: any;
isOnline?: any;
lastSeen?: any;
}
2 changes: 2 additions & 0 deletions src/api/model/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ export interface Contact {
type: string;
verifiedLevel: any;
verifiedName: any;
isOnline?: any;
lastSeen?: any;
}
4 changes: 4 additions & 0 deletions src/api/model/group-change-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum GroupChangeEvent {
Remove = 'remove',
Add = 'add',
}
2 changes: 1 addition & 1 deletion src/api/model/group-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Id } from './id';
import { Id } from '.';

export interface GroupMetadata {
id: Id;
Expand Down
11 changes: 11 additions & 0 deletions src/api/model/group-notification-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum GroupNotificationType {
Add = 'add',
Inivite = 'invite',
Remove = 'remove',
Leave = 'leave',
Subject = 'subject',
Description = 'description',
Picture = 'picture',
Announce = 'announce',
Restrict = 'restrict',
}
7 changes: 7 additions & 0 deletions src/api/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export { Chat } from './chat';
export { ChatState } from './chat-state';
export { Contact } from './contact';
export { GroupChangeEvent } from './group-change-event';
export { GroupMetadata } from './group-metadata';
export { GroupNotificationType } from './group-notification-type';
export { Id } from './id';
export { Message } from './message';
export { ParticipantEvent } from './participant-event';
export { PartialMessage } from './partial-message';
9 changes: 9 additions & 0 deletions src/api/model/live-location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface LiveLocation {
id: string;
lat: number;
lng: number;
speed: number;
lastUpdated: number;
accuracy: number;
degrees: any;
}
14 changes: 14 additions & 0 deletions src/api/model/message-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export enum MessageTypes {
TEXT = 'chat',
AUDIO = 'audio',
VOICE = 'ptt',
IMAGE = 'image',
VIDEO = 'video',
DOCUMENT = 'document',
STICKER = 'sticker',
LOCATION = 'location',
CONTACT_CARD = 'vcard',
CONTACT_CARD_MULTI = 'multi_vcard',
REVOKED = 'revoked',
UNKNOWN = 'unknown',
}
8 changes: 7 additions & 1 deletion src/api/model/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ export interface Message {
id: string;
body: string;
type: string;
mimetype?: string;
lat?: string;
lng?: string;
loc?: string;
t: number;
notifyName: string;
from: string;
to: string;
author: string;
self: string;
duration?: string | number;
ack: number;
invis: boolean;
isNewMsg: boolean;
Expand All @@ -16,6 +20,7 @@ export interface Message {
broadcast: boolean;
isForwarded: boolean;
labels: any[];
caption: string;
sender: {
id: string;
name: string;
Expand Down Expand Up @@ -95,6 +100,7 @@ export interface Message {
presence: { id: string; chatstates: any[] };
};
chatId: string;
quotedMsg: any;
quotedMsgObj: any;
mediaData: {};
}
24 changes: 24 additions & 0 deletions src/api/model/partial-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export interface PartialMessage {
id: ID;
body: string;
type: string;
t: number;
notifyName: string;
from: string;
to: string;
self: string;
ack: number;
invis: boolean;
star: boolean;
broadcast: boolean;
mentionedJidList: any[];
isForwarded: boolean;
labels: any[];
}

interface ID {
fromMe: boolean;
remote: string;
id: string;
_serialized: string;
}
7 changes: 7 additions & 0 deletions src/api/model/participant-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { GroupChangeEvent, Id } from '.';

export interface ParticipantEvent {
by: Id;
action: GroupChangeEvent;
who: [Id];
}
Loading

0 comments on commit 83f3b79

Please sign in to comment.