Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

feat: refactor frontend code (#120)

Aldino Kemal3507cc90e8cb
diff --git a/src/cmd/root.go b/src/cmd/root.go
index 247a519e..7dca1685 100644
--- a/src/cmd/root.go
+++ b/src/cmd/root.go
@@ -27,8 +27,8 @@ import (
)
var (
- EmbedViews embed.FS
- EmbedViewsComponent embed.FS
+ EmbedIndex embed.FS
+ EmbedViews embed.FS
)
// rootCmd represents the base command when called without any subcommands
@@ -61,17 +61,16 @@ func runRest(_ *cobra.Command, _ []string) {
log.Fatalln(err)
}
- engine := html.NewFileSystem(http.FS(EmbedViews), ".html")
+ engine := html.NewFileSystem(http.FS(EmbedIndex), ".html")
engine.AddFunc("isEnableBasicAuth", func(token any) bool {
return token != nil
})
app := fiber.New(fiber.Config{
- Views: engine,
- BodyLimit: 50 * 1024 * 1024,
+ Views: engine,
})
app.Static("/statics", "./statics")
app.Use("/components", filesystem.New(filesystem.Config{
- Root: http.FS(EmbedViewsComponent),
+ Root: http.FS(EmbedViews),
PathPrefix: "views/components",
Browse: true,
}))
@@ -141,9 +140,9 @@ func runRest(_ *cobra.Command, _ []string) {
}
// Execute adds all child commands to the root command and sets flags appropriately.
-func Execute(embedViews embed.FS, embedViewsComponent embed.FS) {
+func Execute(embedIndex embed.FS, embedViews embed.FS) {
+ EmbedIndex = embedIndex
EmbedViews = embedViews
- EmbedViewsComponent = embedViewsComponent
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
diff --git a/src/go.mod b/src/go.mod
index 5fc71ab8..ce0fdef6 100644
--- a/src/go.mod
+++ b/src/go.mod
@@ -18,7 +18,7 @@ require (
github.com/stretchr/testify v1.9.0
github.com/valyala/fasthttp v1.52.0
go.mau.fi/libsignal v0.1.0
- go.mau.fi/whatsmeow v0.0.0-20240308162537-79d9175fa09b
+ go.mau.fi/whatsmeow v0.0.0-20240312193055-9b989e1cc696
google.golang.org/protobuf v1.33.0
)
diff --git a/src/go.sum b/src/go.sum
index 9adba982..17447319 100644
--- a/src/go.sum
+++ b/src/go.sum
@@ -96,6 +96,8 @@ go.mau.fi/util v0.4.0 h1:S2X3qU4pUcb/vxBRfAuZjbrR9xVMAXSjQojNBLPBbhs=
go.mau.fi/util v0.4.0/go.mod h1:leeiHtgVBuN+W9aDii3deAXnfC563iN3WK6BF8/AjNw=
go.mau.fi/whatsmeow v0.0.0-20240308162537-79d9175fa09b h1:Jk0/Lu6LdLD4kh0L9Q+06n7EefcS8ZDAKpwGeX7C4YQ=
go.mau.fi/whatsmeow v0.0.0-20240308162537-79d9175fa09b/go.mod h1:lQHbhaG/fI+6hfGqz5Vzn2OBJBEZ05H0kCP6iJXriN4=
+go.mau.fi/whatsmeow v0.0.0-20240312193055-9b989e1cc696 h1:F9ytx1yzfoclCS4DoEqQb1M0E5XpcX2j5dX8bIZjGFE=
+go.mau.fi/whatsmeow v0.0.0-20240312193055-9b989e1cc696/go.mod h1:lQHbhaG/fI+6hfGqz5Vzn2OBJBEZ05H0kCP6iJXriN4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
diff --git a/src/main.go b/src/main.go
index 80deb90a..2441d04a 100644
--- a/src/main.go
+++ b/src/main.go
@@ -6,11 +6,11 @@ import (
)
//go:embed views/index.html
-var embedViews embed.FS
+var embedIndex embed.FS
//go:embed views
-var embedViewsComponent embed.FS
+var embedViews embed.FS
func main() {
- cmd.Execute(embedViews, embedViewsComponent)
+ cmd.Execute(embedIndex, embedViews)
}
diff --git a/src/views/components/AccountAvatar.js b/src/views/components/AccountAvatar.js
new file mode 100644
index 00000000..2e602cbd
--- /dev/null
+++ b/src/views/components/AccountAvatar.js
@@ -0,0 +1,111 @@
+export default {
+ name: 'AccountAvatar',
+ data() {
+ return {
+ type: 'user',
+ phone: '',
+ image: null,
+ loading: false,
+ is_preview: false,
+ is_community: false,
+ }
+ },
+ computed: {
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
+ }
+ },
+ methods: {
+ async openModal() {
+ this.handleReset();
+ $('#modalUserAvatar').modal('show');
+ },
+ async handleSubmit() {
+ try {
+ await this.submitApi();
+ showSuccessInfo("Avatar fetched")
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ let response = await window.http.get(`/user/avatar?phone=${this.phone_id}&is_preview=${this.is_preview}&is_community=${this.is_community}`)
+ this.image = response.data.results.url;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
+ },
+ handleReset() {
+ this.phone = '';
+ this.image = null;
+ this.type = 'user';
+ }
+ },
+ template: `
+ <div class="green card" @click="openModal" style="cursor: pointer;">
+ <div class="content">
+ <div class="header">Avatar</div>
+ <div class="description">
+ You can search someone avatar by phone
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal UserAvatar -->
+ <div class="ui small modal" id="modalUserAvatar">
+ <i class="close icon"></i>
+ <div class="header">
+ Search User Avatar
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <div class="field">
+ <label>Type</label>
+ <select name="type" v-model="type" aria-label="type">
+ <option value="group">Group Message</option>
+ <option value="user">Private Message</option>
+ </select>
+ </div>
+ <div class="field">
+ <label>Phone</label>
+ <input v-model="phone" type="text" placeholder="6289..."
+ aria-label="phone">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
+ </div>
+
+ <div class="field">
+ <label>Preview</label>
+ <div class="ui toggle checkbox">
+ <input type="checkbox" aria-label="compress" v-model="is_preview">
+ <label>Check for small size image</label>
+ </div>
+ </div>
+
+ <div class="field">
+ <label>Community</label>
+ <div class="ui toggle checkbox">
+ <input type="checkbox" aria-label="compress" v-model="is_community">
+ <label>Check is it's community image</label>
+ </div>
+ </div>
+
+ <button type="button" class="ui primary button" :class="{'loading': loading}"
+ @click="handleSubmit">
+ Search
+ </button>
+ </form>
+
+ <div v-if="image != null" class="center">
+ <img :src="image" alt="profile picture" style="padding-top: 10px; max-height: 200px">
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/AccountGroup.js b/src/views/components/AccountGroup.js
new file mode 100644
index 00000000..a72ce12a
--- /dev/null
+++ b/src/views/components/AccountGroup.js
@@ -0,0 +1,114 @@
+export default {
+ name: 'AccountGroup',
+ data() {
+ return {
+ groups: []
+ }
+ },
+ methods: {
+ async openModal() {
+ try {
+ this.dtClear()
+ await this.submitApi();
+ $('#modalUserGroup').modal('show');
+ this.dtRebuild()
+ showSuccessInfo("Groups fetched")
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ dtClear() {
+ $('#account_groups_table').DataTable().destroy();
+ },
+ dtRebuild() {
+ $('#account_groups_table').DataTable({
+ "pageLength": 100,
+ "reloadData": true,
+ }).draw();
+ },
+ async handleLeaveGroup(group_id) {
+ try {
+ const ok = confirm("Are you sure to leave this group?");
+ if (!ok) return;
+
+ await this.leaveGroupApi(group_id);
+ this.dtClear()
+ await this.submitApi();
+ this.dtRebuild()
+ showSuccessInfo("Group left")
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async leaveGroupApi(group_id) {
+ try {
+ let payload = new FormData();
+ payload.append("group_id", group_id)
+ await window.http.post(`/group/leave`, payload)
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+
+ }
+ },
+ async submitApi() {
+ try {
+ let response = await window.http.get(`/user/my/groups`)
+ this.groups = response.data.results.data;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ }
+ },
+ formatDate: function (value) {
+ if (!value) return ''
+ return moment(value).format('LLL');
+ }
+ },
+ template: `
+ <div class="green card" @click="openModal" style="cursor: pointer">
+ <div class="content">
+ <div class="header">My List Groups</div>
+ <div class="description">
+ Display all groups you joined
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal AccountGroup -->
+ <div class="ui small modal" id="modalUserGroup">
+ <i class="close icon"></i>
+ <div class="header">
+ My Group List
+ </div>
+ <div class="content">
+ <table class="ui celled table" id="account_groups_table">
+ <thead>
+ <tr>
+ <th>Group ID</th>
+ <th>Name</th>
+ <th>Participants</th>
+ <th>Created At</th>
+ <th>Action</th>
+ </tr>
+ </thead>
+ <tbody v-if="groups != null">
+ <tr v-for="g in groups">
+ <td>{{ g.JID.split('@')[0] }}</td>
+ <td>{{ g.Name }}</td>
+ <td>{{ g.Participants.length }}</td>
+ <td>{{ formatDate(g.GroupCreated) }}</td>
+ <td>
+ <button class="ui red tiny button" @click="handleLeaveGroup(g.JID)">Leave</button>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/AccountPrivacy.js b/src/views/components/AccountPrivacy.js
new file mode 100644
index 00000000..46061b80
--- /dev/null
+++ b/src/views/components/AccountPrivacy.js
@@ -0,0 +1,57 @@
+export default {
+ name: 'AccountPrivacy',
+ data() {
+ return {
+ data_privacy: null
+ }
+ },
+ methods: {
+ async openModal() {
+ try {
+ await this.submitApi();
+ $('#modalUserPrivacy').modal('show');
+ showSuccessInfo("Privacy fetched")
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ try {
+ let response = await window.http.get(`/user/my/privacy`)
+ this.data_privacy = response.data.results;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ }
+ },
+ },
+ template: `
+ <div class="green card" @click="openModal" style="cursor: pointer">
+ <div class="content">
+ <div class="header">My Privacy Setting</div>
+ <div class="description">
+ Get your privacy settings
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal UserPrivacy -->
+ <div class="ui small modal" id="modalUserPrivacy">
+ <i class="close icon"></i>
+ <div class="header">
+ My Privacy
+ </div>
+ <div class="content">
+ <ol v-if="data_privacy != null">
+ <li>Who can add Group : <b>{{ data_privacy.group_add }}</b></li>
+ <li>Who can see my Last Seen : <b>{{ data_privacy.last_seen }}</b></li>
+ <li>Who can see my Status : <b>{{ data_privacy.status }}</b></li>
+ <li>Who can see my Profile : <b>{{ data_privacy.profile }}</b></li>
+ <li>Read Receipts : <b>{{ data_privacy.read_receipts }}</b></li>
+ </ol>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/AccountUserInfo.js b/src/views/components/AccountUserInfo.js
new file mode 100644
index 00000000..4bc2aa0c
--- /dev/null
+++ b/src/views/components/AccountUserInfo.js
@@ -0,0 +1,112 @@
+export default {
+ name: 'AccountUserInfo',
+ data() {
+ return {
+ type: 'user',
+ phone: '',
+ //
+ name: null,
+ status: null,
+ devices: [],
+ //
+ loading: false,
+ }
+ },
+
+ computed: {
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
+ }
+ },
+ methods: {
+ async openModal() {
+ this.handleReset();
+ $('#modalUserInfo').modal('show');
+ },
+ async handleSubmit() {
+ try {
+ await this.submitApi();
+ showSuccessInfo("Info fetched")
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ let response = await window.http.get(`/user/info?phone=${this.phone_id}`)
+ this.name = response.data.results.verified_name;
+ this.status = response.data.results.status;
+ this.devices = response.data.results.devices;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
+ },
+ handleReset() {
+ this.phone = '';
+ this.name = null;
+ this.status = null;
+ this.devices = [];
+ this.type = 'user';
+ }
+ },
+ template: `
+ <div class="green card" @click="openModal" style="cursor: pointer;">
+ <div class="content">
+ <div class="header">User Info</div>
+ <div class="description">
+ You can search someone user info by phone
+ </div>
+ </div>
+ </div>
+
+
+ <!-- Modal UserInfo -->
+ <div class="ui small modal" id="modalUserInfo">
+ <i class="close icon"></i>
+ <div class="header">
+ Search User Information
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <div class="field">
+ <label>Type</label>
+ <select name="type" v-model="type" aria-label="type">
+ <option value="user">Private Message</option>
+ </select>
+ </div>
+ <div class="field">
+ <label>Phone</label>
+ <input v-model="phone" type="text" placeholder="6289..."
+ aria-label="phone">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
+ </div>
+
+ <button type="button" class="ui primary button" :class="{'loading': loading}"
+ @click="handleSubmit">
+ Search
+ </button>
+ </form>
+
+ <div v-if="devices.length > 0" class="center">
+ <ol>
+ <li>Nama: {{ name }}</li>
+ <li>Status: {{ status }}</li>
+ <li>Device:
+ <ul>
+ <li v-for="d in devices">
+ {{ d.Device }}
+ </li>
+ </ul>
+ </li>
+ </ol>
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/AppLogin.js b/src/views/components/AppLogin.js
new file mode 100644
index 00000000..b276e7fb
--- /dev/null
+++ b/src/views/components/AppLogin.js
@@ -0,0 +1,72 @@
+export default {
+ name: 'AppLogin',
+ data() {
+ return {
+ login_link: '',
+ login_duration_sec: 0,
+ }
+ },
+ methods: {
+ async openModal() {
+ try {
+ await this.submitApi();
+ $('#modalLogin').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ try {
+ let response = await window.http.get(`/app/login`)
+ let results = response.data.results;
+ this.login_link = results.qr_link;
+ this.login_duration_sec = results.qr_duration;
+ } catch (error) {
+ if (error.response) {
+ throw Error(error.response.data.message)
+ }
+ throw Error(error.message)
+ }
+ }
+ },
+ template: `
+ <div class="green card" @click="openModal" style="cursor: pointer">
+ <div class="content">
+ <div class="header">Login</div>
+ <div class="description">
+ Scan your QRCode and you can use all this API feature
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal Login -->
+ <div class="ui small modal" id="modalLogin">
+ <i class="close icon"></i>
+ <div class="header">
+ Login Whatsapp
+ </div>
+ <div class="image content">
+ <div class="ui medium image">
+ <img :src="login_link" alt="qrCodeLogin">
+ </div>
+ <div class="description">
+ <div class="ui header">Please scan to connect</div>
+ <p>Open Setting > Linked Devices > Link Device</p>
+ <div style="padding-top: 50px;">
+ <i>Refresh QR Code in {{ login_duration_sec }} seconds to avoid link expiration</i>
+ </div>
+ </div>
+ </div>
+ <div class="actions">
+ <div class="ui approve positive right labeled icon button" @click="submitApi">
+ Refresh QR Code
+ <i class="refresh icon"></i>
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/AppLogout.js b/src/views/components/AppLogout.js
new file mode 100644
index 00000000..f0ed901d
--- /dev/null
+++ b/src/views/components/AppLogout.js
@@ -0,0 +1,38 @@
+export default {
+ name: 'AppLogout',
+ methods: {
+ async handleSubmit() {
+ try {
+ await this.submitApi()
+ showSuccessInfo("Logout success")
+
+ // fetch devices
+ this.$emit('reload-devices')
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+
+ async submitApi() {
+ try {
+ await http.get(`/app/logout`)
+ } catch (error) {
+ if (error.response) {
+ throw Error(error.response.data.message)
+ }
+ throw Error(error.message)
+ }
+
+ }
+ },
+ template: `
+ <div class="green card" @click="handleSubmit" style="cursor: pointer">
+ <div class="content">
+ <div class="header">Logout</div>
+ <div class="description">
+ Remove your login session in application
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/AppReconnect.js b/src/views/components/AppReconnect.js
new file mode 100644
index 00000000..dcc507b8
--- /dev/null
+++ b/src/views/components/AppReconnect.js
@@ -0,0 +1,37 @@
+export default {
+ name: 'AppReconnect',
+ methods: {
+ async handleSubmit() {
+ try {
+ await this.submitApi()
+ showSuccessInfo("Reconnect success")
+
+ // fetch devices
+ this.$emit('reload-devices')
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ try {
+ await window.http.get(`/app/reconnect`)
+ } catch (error) {
+ if (error.response) {
+ throw Error(error.response.data.message)
+ }
+ throw Error(error.message)
+ }
+ }
+ },
+ template: `
+ <div class="green card" @click="handleSubmit" style="cursor: pointer">
+ <div class="content">
+ <div class="header">Reconnect</div>
+ <div class="description">
+ Reconnect to whatsapp server, please do this if your api doesn't work or your application is down or
+ restart
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/MessageReact.js b/src/views/components/MessageReact.js
new file mode 100644
index 00000000..d5889658
--- /dev/null
+++ b/src/views/components/MessageReact.js
@@ -0,0 +1,111 @@
+export default {
+ name: 'ReactMessage',
+ data() {
+ return {
+ type: 'user',
+ phone: '',
+ message_id: '',
+ emoji: '',
+ loading: false,
+ }
+ },
+ computed: {
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
+ }
+ },
+ methods: {
+ openModal() {
+ $('#modalMessageReaction').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ },
+ async handleSubmit() {
+ try {
+ let response = await this.submitApi()
+ showSuccessInfo(response)
+ $('#modalMessageReaction').modal('hide');
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ const payload = {phone: this.phone_id, emoji: this.emoji}
+ let response = await window.http.post(`/message/${this.message_id}/reaction`, payload)
+ this.handleReset();
+ return response.data.message;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
+ },
+ handleReset() {
+ this.phone = '';
+ this.message_id = '';
+ this.emoji = '';
+ this.type = 'user';
+ },
+ },
+ template: `
+ <div class="red card" @click="openModal()" style="cursor: pointer">
+ <div class="content">
+ <a class="ui red right ribbon label">Message</a>
+ <div class="header">React Message</div>
+ <div class="description">
+ any message in private or group chat
+ </div>
+ </div>
+ </div>
+
+
+ <!-- Modal MessageReaction -->
+ <div class="ui small modal" id="modalMessageReaction">
+ <i class="close icon"></i>
+ <div class="header">
+ React Message
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <div class="field">
+ <label>Type</label>
+ <select name="type" v-model="type" aria-label="type">
+ <option value="group">Group Message</option>
+ <option value="user">Private Message</option>
+ </select>
+ </div>
+ <div class="field">
+ <label>Phone / Group ID</label>
+ <input v-model="phone" type="text" placeholder="6289..."
+ aria-label="phone">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
+ </div>
+ <div class="field">
+ <label>Message ID</label>
+ <input v-model="message_id" type="text" placeholder="Please enter your message id"
+ aria-label="message id">
+ </div>
+ <div class="field">
+ <label>Emoji</label>
+ <input v-model="emoji" type="text" placeholder="Please enter emoji"
+ aria-label="message id">
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <div class="ui approve positive right labeled icon button" :class="{'loading': this.loading}"
+ @click="handleSubmit">
+ Send
+ <i class="send icon"></i>
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/MessageRevoke.js b/src/views/components/MessageRevoke.js
new file mode 100644
index 00000000..959919b9
--- /dev/null
+++ b/src/views/components/MessageRevoke.js
@@ -0,0 +1,103 @@
+export default {
+ name: 'Message',
+ data() {
+ return {
+ type: 'user',
+ phone: '',
+ message_id: '',
+ loading: false,
+ }
+ },
+ computed: {
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
+ }
+ },
+ methods: {
+ openModal() {
+ $('#modalMessageRevoke').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ },
+ async handleSubmit() {
+ try {
+ let response = await this.submitApi()
+ showSuccessInfo(response)
+ $('#modalMessageRevoke').modal('hide');
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ const payload = {phone: this.phone_id}
+ let response = await window.http.post(`/message/${this.message_id}/revoke`, payload)
+ this.handleReset();
+ return response.data.message;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
+ },
+ handleReset() {
+ this.phone = '';
+ this.message_id = '';
+ this.type = 'user';
+ },
+ },
+ template: `
+ <div class="red card" @click="openModal()" style="cursor: pointer">
+ <div class="content">
+ <a class="ui red right ribbon label">Message</a>
+ <div class="header">Revoke Message</div>
+ <div class="description">
+ any message in private or group chat
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal MessageRevoke -->
+ <div class="ui small modal" id="modalMessageRevoke">
+ <i class="close icon"></i>
+ <div class="header">
+ Revoke Message
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <div class="field">
+ <label>Type</label>
+ <select name="type" v-model="type" aria-label="type">
+ <option value="group">Group Message</option>
+ <option value="user">Private Message</option>
+ </select>
+ </div>
+ <div class="field">
+ <label>Phone / Group ID</label>
+ <input v-model="phone" type="text" placeholder="6289..."
+ aria-label="phone">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
+ </div>
+ <div class="field">
+ <label> Message ID</label>
+ <input v-model="message_id" type="text" placeholder="Please enter your message id"
+ aria-label="message id">
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <div class="ui approve positive right labeled icon button" :class="{'loading': this.loading}"
+ @click="handleSubmit">
+ Send
+ <i class="send icon"></i>
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/MessageUpdate.js b/src/views/components/MessageUpdate.js
index 6ca46442..0138b641 100644
--- a/src/views/components/MessageUpdate.js
+++ b/src/views/components/MessageUpdate.js
@@ -1,81 +1,74 @@
export default {
- name: 'Update Message',
+ name: 'UpdateMessage',
data() {
return {
- update_type: 'user',
- update_phone: '',
- update_message_id: '',
- update_new_message: '',
- update_loading: false,
+ type: 'user',
+ phone: '',
+ message_id: '',
+ new_message: '',
+ loading: false,
}
},
computed: {
- update_phone_id() {
- return this.update_type === 'user' ? `${this.update_phone}@${window.TYPEUSER}` : `${this.update_phone}@${window.TYPEGROUP}`
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
}
},
methods: {
- messageEditModal() {
- $('#modalMessageEdit').modal({
+ openModal() {
+ $('#modalMessageUpdate').modal({
onApprove: function () {
return false;
}
}).modal('show');
},
- async messageEditProcess() {
+ async handleSubmit() {
try {
- let response = await this.messageEditApi()
+ let response = await this.submitApi()
showSuccessInfo(response)
- $('#modalMessageEdit').modal('hide');
+ $('#modalMessageUpdate').modal('hide');
} catch (err) {
showErrorInfo(err)
}
},
- messageEditApi() {
- return new Promise(async (resolve, reject) => {
- try {
- this.update_loading = true;
-
- const payload = {
- phone: this.update_phone_id,
- message: this.update_new_message
- }
+ async submitApi() {
+ this.loading = true;
+ try {
+ const payload = {phone: this.phone_id, message: this.new_message}
- let response = await http.post(`/message/${this.update_message_id}/update`, payload)
- this.messageEditReset();
- resolve(response.data.message)
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- } finally {
- this.update_loading = false;
+ let response = await window.http.post(`/message/${this.message_id}/update`, payload)
+ this.handleReset();
+ return response.data.message;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
}
- })
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
},
- messageEditReset() {
- this.update_type = 'user';
- this.update_phone = '';
- this.update_message_id = '';
- this.update_new_message = '';
- this.update_loading = false;
+ handleReset() {
+ this.type = 'user';
+ this.phone = '';
+ this.message_id = '';
+ this.new_message = '';
+ this.loading = false;
},
},
template: `
- <div class="red card" @click="messageEditModal()" style="cursor: pointer">
+ <div class="red card" @click="openModal()" style="cursor: pointer">
<div class="content">
<a class="ui red right ribbon label">Message</a>
- <div class="header">Edit Message</div>
+ <div class="header">Update Message</div>
<div class="description">
Update your sent message
</div>
</div>
</div>
- <!-- Modal MessageEdit -->
- <div class="ui small modal" id="modalMessageEdit">
+ <!-- Modal MessageUpdate -->
+ <div class="ui small modal" id="modalMessageUpdate">
<i class="close icon"></i>
<div class="header">
Update Message
@@ -84,32 +77,32 @@ export default {
<form class="ui form">
<div class="field">
<label>Type</label>
- <select name="update_type" v-model="update_type" aria-label="type">
+ <select name="type" v-model="type" aria-label="type">
<option value="group">Group Message</option>
<option value="user">Private Message</option>
</select>
</div>
<div class="field">
<label>Phone / Group ID</label>
- <input v-model="update_phone" type="text" placeholder="6289..."
+ <input v-model="phone" type="text" placeholder="6289..."
aria-label="phone">
- <input :value="update_phone_id" disabled aria-label="whatsapp_id">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
</div>
<div class="field">
<label>Message ID</label>
- <input v-model="update_message_id" type="text" placeholder="Please enter your message id"
+ <input v-model="message_id" type="text" placeholder="Please enter your message id"
aria-label="message id">
</div>
<div class="field">
<label>New Message</label>
- <textarea v-model="update_new_message" type="text" placeholder="Hello this is your new message text, you can edit before 15 minutes after sent."
+ <textarea v-model="new_message" type="text" placeholder="Hello this is your new message text, you can edit before 15 minutes after sent."
aria-label="message"></textarea>
</div>
</form>
</div>
<div class="actions">
- <div class="ui approve positive right labeled icon button" :class="{'loading': this.update_loading}"
- @click="messageEditProcess">
+ <div class="ui approve positive right labeled icon button" :class="{'loading': this.loading}"
+ @click="handleSubmit">
Update
<i class="send icon"></i>
</div>
diff --git a/src/views/components/SendAudio.js b/src/views/components/SendAudio.js
new file mode 100644
index 00000000..7651ddd9
--- /dev/null
+++ b/src/views/components/SendAudio.js
@@ -0,0 +1,107 @@
+export default {
+ name: 'Send',
+ data() {
+ return {
+ phone: '',
+ type: 'user',
+ loading: false,
+ }
+ },
+ computed: {
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
+ }
+ },
+ methods: {
+ openModal() {
+ $('#modalAudioSend').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ },
+ async handleSubmit() {
+ try {
+ let response = await this.submitApi()
+ showSuccessInfo(response)
+ $('#modalAudioSend').modal('hide');
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ let payload = new FormData();
+ payload.append("phone", this.phone_id)
+ payload.append("audio", $("#file_audio")[0].files[0])
+ const response = await window.http.post(`/send/audio`, payload)
+ this.handleReset();
+ return response.data.message;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
+ },
+ handleReset() {
+ this.phone = '';
+ this.type = 'user';
+ $("#file_audio").val('');
+ },
+ },
+ template: `
+ <div class="blue card" @click="openModal()" style="cursor: pointer">
+ <div class="content">
+ <a class="ui blue right ribbon label">Send</a>
+ <div class="header">Send Audio</div>
+ <div class="description">
+ Send audio to user or group
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal SendAudio -->
+ <div class="ui small modal" id="modalAudioSend">
+ <i class="close icon"></i>
+ <div class="header">
+ Send Audio
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <div class="field">
+ <label>Type</label>
+ <select name="type" v-model="type" aria-label="type">
+ <option value="group">Group Message</option>
+ <option value="user">Private Message</option>
+ </select>
+ </div>
+ <div class="field">
+ <label>Phone / Group ID</label>
+ <input v-model="phone" type="text" placeholder="6289..."
+ aria-label="phone">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
+ </div>
+ <div class="field" style="padding-bottom: 30px">
+ <label>Audio</label>
+ <input type="file" style="display: none" accept="audio/*" id="file_audio"/>
+ <label for="file_audio" class="ui positive medium green left floated button" style="color: white">
+ <i class="ui upload icon"></i>
+ Upload
+ </label>
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <div class="ui approve positive right labeled icon button" :class="{'loading': this.loading}"
+ @click="handleSubmit">
+ Send
+ <i class="send icon"></i>
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/SendContact.js b/src/views/components/SendContact.js
new file mode 100644
index 00000000..21239620
--- /dev/null
+++ b/src/views/components/SendContact.js
@@ -0,0 +1,117 @@
+export default {
+ name: 'SendContact',
+ data() {
+ return {
+ type: 'user',
+ phone: '',
+ card_name: '',
+ card_phone: '',
+ loading: false,
+ }
+ },
+ computed: {
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
+ }
+ },
+ methods: {
+ openModal() {
+ $('#modalSendContact').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ },
+ async handleSubmit() {
+ try {
+ this.loading = true;
+ let response = await this.submitApi()
+ showSuccessInfo(response)
+ $('#modalSendContact').modal('hide');
+ } catch (err) {
+ showErrorInfo(err)
+ } finally {
+ this.loading = false;
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ const payload = {
+ phone: this.phone_id,
+ contact_name: this.card_name,
+ contact_phone: this.card_phone
+ }
+ let response = await window.http.post(`/send/contact`, payload)
+ this.handleReset();
+ return response.data.message;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
+ },
+ handleReset() {
+ this.phone = '';
+ this.card_name = '';
+ this.card_phone = '';
+ this.type = 'user';
+ },
+ },
+ template: `
+ <div class="blue card" @click="openModal()" style="cursor: pointer">
+ <div class="content">
+ <a class="ui blue right ribbon label">Send</a>
+ <div class="header">Send Contact</div>
+ <div class="description">
+ Send contact to user or group
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal SendContact -->
+ <div class="ui small modal" id="modalSendContact">
+ <i class="close icon"></i>
+ <div class="header">
+ Send Contact
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <div class="field">
+ <label>Type</label>
+ <select name="type" v-model="type" aria-label="type">
+ <option value="group">Group Message</option>
+ <option value="user">Private Message</option>
+ </select>
+ </div>
+ <div class="field">
+ <label>Phone / Group ID</label>
+ <input v-model="phone" type="text" placeholder="6289..."
+ aria-label="phone">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
+ </div>
+ <div class="field">
+ <label>Contact Name</label>
+ <input v-model="card_name" type="text" placeholder="Please enter contact name"
+ aria-label="contact name">
+ </div>
+ <div class="field">
+ <label>Contact Phone</label>
+ <input v-model="card_phone" type="text" placeholder="Please enter contact phone"
+ aria-label="contact phone">
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <div class="ui approve positive right labeled icon button" :class="{'loading': this.loading}"
+ @click="handleSubmit">
+ Send
+ <i class="send icon"></i>
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/SendFile.js b/src/views/components/SendFile.js
new file mode 100644
index 00000000..7039f723
--- /dev/null
+++ b/src/views/components/SendFile.js
@@ -0,0 +1,122 @@
+export default {
+ name: 'SendFile',
+ props: {
+ maxFileSize: {
+ type: String,
+ required: true,
+ }
+ },
+ data() {
+ return {
+ caption: '',
+ type: 'user',
+ phone: '',
+ loading: false,
+ }
+ },
+ computed: {
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
+ }
+ },
+ methods: {
+ openModal() {
+ $('#modalSendFile').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ },
+ async handleSubmit() {
+ try {
+ let response = await this.submitApi()
+ showSuccessInfo(response)
+ $('#modalSendFile').modal('hide');
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ let payload = new FormData();
+ payload.append("caption", this.caption)
+ payload.append("phone", this.phone_id)
+ payload.append("file", $("#file_file")[0].files[0])
+ let response = await window.http.post(`/send/file`, payload)
+ this.handleReset();
+ return response.data.message;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
+ },
+ handleReset() {
+ this.caption = '';
+ this.phone = '';
+ this.type = 'user';
+ $("#file_file").val('');
+ },
+ },
+ template: `
+ <div class="blue card" @click="openModal()" style="cursor: pointer">
+ <div class="content">
+ <a class="ui blue right ribbon label">Send</a>
+ <div class="header">Send File</div>
+ <div class="description">
+ Send any file up to
+ <div class="ui blue horizontal label">{{ maxFileSize }}</div>
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal SendFile -->
+ <div class="ui small modal" id="modalSendFile">
+ <i class="close icon"></i>
+ <div class="header">
+ Send File
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <div class="field">
+ <label>Type</label>
+ <select name="type" v-model="type" aria-label="type">
+ <option value="group">Group Message</option>
+ <option value="user">Private Message</option>
+ </select>
+ </div>
+ <div class="field">
+ <label>Phone / Group ID</label>
+ <input v-model="phone" type="text" placeholder="6289..."
+ aria-label="phone">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
+ </div>
+ <div class="field">
+ <label>Caption</label>
+ <textarea v-model="caption" placeholder="Type some caption (optional)..."
+ aria-label="caption"></textarea>
+ </div>
+ <div class="field" style="padding-bottom: 30px">
+ <label>File</label>
+ <input type="file" style="display: none" id="file_file">
+ <label for="file_file" class="ui positive medium green left floated button" style="color: white">
+ <i class="ui upload icon"></i>
+ Upload file
+ </label>
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <div class="ui approve positive right labeled icon button" :class="{'loading': this.loading}"
+ @click="handleSubmit">
+ Send
+ <i class="send icon"></i>
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/SendImage.js b/src/views/components/SendImage.js
new file mode 100644
index 00000000..04ae09e9
--- /dev/null
+++ b/src/views/components/SendImage.js
@@ -0,0 +1,139 @@
+export default {
+ name: 'SendImage',
+ data() {
+ return {
+ phone: '',
+ view_once: false,
+ compress: false,
+ caption: '',
+ type: 'user',
+ loading: false,
+ selected_file: null
+ }
+ },
+ computed: {
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
+ }
+ },
+ methods: {
+ openModal() {
+ $('#modalSendImage').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ },
+ async handleSubmit() {
+ try {
+ let response = await this.submitApi()
+ showSuccessInfo(response)
+ $('#modalSendImage').modal('hide');
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ let payload = new FormData();
+ payload.append("phone", this.phone_id)
+ payload.append("view_once", this.view_once)
+ payload.append("compress", this.compress)
+ payload.append("caption", this.caption)
+ payload.append('image', $("#file_image")[0].files[0])
+
+ let response = await window.http.post(`/send/image`, payload)
+ this.handleReset();
+ return response.data.message;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
+ },
+ handleReset() {
+ this.view_once = false;
+ this.compress = false;
+ this.phone = '';
+ this.caption = '';
+ this.type = 'user';
+ $("#file_image").val('');
+ },
+ },
+ template: `
+ <div class="blue card" @click="openModal()" style="cursor:pointer;">
+ <div class="content">
+ <a class="ui blue right ribbon label">Send</a>
+ <div class="header">Send Image</div>
+ <div class="description">
+ Send image with
+ <div class="ui blue horizontal label">jpg/jpeg/png</div>
+ type
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal SendImage -->
+ <div class="ui small modal" id="modalSendImage">
+ <i class="close icon"></i>
+ <div class="header">
+ Send Image
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <div class="field">
+ <label>Type</label>
+ <select name="type" v-model="type" aria-label="type">
+ <option value="group">Group Message</option>
+ <option value="user">Private Message</option>
+ </select>
+ </div>
+ <div class="field">
+ <label>Phone / Group ID</label>
+ <input v-model="phone" type="text" placeholder="6289..."
+ aria-label="phone">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
+ </div>
+ <div class="field">
+ <label>Caption</label>
+ <textarea v-model="caption" type="text" placeholder="Hello this is image caption"
+ aria-label="caption"></textarea>
+ </div>
+ <div class="field">
+ <label>View Once</label>
+ <div class="ui toggle checkbox">
+ <input type="checkbox" aria-label="view once" v-model="view_once">
+ <label>Check for enable one time view</label>
+ </div>
+ </div>
+ <div class="field">
+ <label>Compress</label>
+ <div class="ui toggle checkbox">
+ <input type="checkbox" aria-label="compress" v-model="compress">
+ <label>Check for compressing image to smaller size</label>
+ </div>
+ </div>
+ <div class="field" style="padding-bottom: 30px">
+ <label>Image</label>
+ <input type="file" style="display: none" id="file_image" accept="image/png,image/jpg,image/jpeg"/>
+ <label for="file_image" class="ui positive medium green left floated button" style="color: white">
+ <i class="ui upload icon"></i>
+ Upload image
+ </label>
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <div class="ui approve positive right labeled icon button" :class="{'loading': this.loading}"
+ @click="handleSubmit">
+ Send
+ <i class="send icon"></i>
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/SendLocation.js b/src/views/components/SendLocation.js
new file mode 100644
index 00000000..ce6c479e
--- /dev/null
+++ b/src/views/components/SendLocation.js
@@ -0,0 +1,115 @@
+export default {
+ name: 'SendLocation',
+ data() {
+ return {
+ type: 'user',
+ phone: '',
+ latitude: '',
+ longitude: '',
+ loading: false,
+ }
+ },
+ computed: {
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
+ }
+ },
+ methods: {
+ openModal() {
+ $('#modalSendLocation').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ },
+ async handleSubmit() {
+ try {
+ let response = await this.submitApi()
+ showSuccessInfo(response)
+ $('#modalSendLocation').modal('hide');
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ const payload = {
+ phone: this.phone_id,
+ latitude: this.latitude,
+ longitude: this.longitude
+ };
+
+ const response = await window.http.post(`/send/location`, payload);
+ this.handleReset();
+ return response.data.message;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
+ },
+ handleReset() {
+ this.phone = '';
+ this.latitude = '';
+ this.longitude = '';
+ this.type = 'user';
+ },
+ },
+ template: `
+ <div class="blue card" @click="openModal()" style="cursor: pointer">
+ <div class="content">
+ <a class="ui blue right ribbon label">Send</a>
+ <div class="header">Send Location</div>
+ <div class="description">
+ Send location to user or group
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal SendLocation -->
+ <div class="ui small modal" id="modalSendLocation">
+ <i class="close icon"></i>
+ <div class="header">
+ Send Location
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <div class="field">
+ <label>Type</label>
+ <select name="type" v-model="type" aria-label="type">
+ <option value="group">Group Message</option>
+ <option value="user">Private Message</option>
+ </select>
+ </div>
+ <div class="field">
+ <label>Phone / Group ID</label>
+ <input v-model="phone" type="text" placeholder="6289..."
+ aria-label="phone">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
+ </div>
+ <div class="field">
+ <label>Location Latitude</label>
+ <input v-model="latitude" type="text" placeholder="Please enter latitude"
+ aria-label="latitude">
+ </div>
+ <div class="field">
+ <label>Location Longitude</label>
+ <input v-model="longitude" type="text" placeholder="Please enter longitude"
+ aria-label="longitude">
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <div class="ui approve positive right labeled icon button" :class="{'loading': this.loading}"
+ @click="handleSubmit">
+ Send
+ <i class="send icon"></i>
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/SendMessage.js b/src/views/components/SendMessage.js
new file mode 100644
index 00000000..6f567796
--- /dev/null
+++ b/src/views/components/SendMessage.js
@@ -0,0 +1,118 @@
+export default {
+ name: 'SendMessage',
+ data() {
+ return {
+ type: 'user',
+ phone: '',
+ text: '',
+ reply_id: '',
+ loading: false,
+ }
+ },
+ computed: {
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
+ }
+ },
+ methods: {
+ openModal() {
+ $('#modalSendMessage').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ },
+ async handleSubmit() {
+ try {
+ let response = await this.submitApi()
+ showSuccessInfo(response)
+ $('#modalSendMessage').modal('hide');
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ const payload = {
+ phone: this.phone_id,
+ message: this.text,
+ }
+ if (this.reply_id !== '') {
+ payload.reply_id = this.reply_id;
+ }
+
+ let response = await window.http.post(`/send/message`, payload)
+ this.handleReset();
+ return response.data.message;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
+ },
+ handleReset() {
+ this.phone = '';
+ this.text = '';
+ this.type = 'user';
+ this.reply_id = '';
+ },
+ },
+ template: `
+ <div class="blue card" @click="openModal()" style="cursor: pointer">
+ <div class="content">
+ <a class="ui blue right ribbon label">Send</a>
+ <div class="header">Send Message</div>
+ <div class="description">
+ Send any message to user or group
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal SendMessage -->
+ <div class="ui small modal" id="modalSendMessage">
+ <i class="close icon"></i>
+ <div class="header">
+ Send Message
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <div class="field">
+ <label>Type</label>
+ <select name="type" v-model="type" aria-label="type">
+ <option value="group">Group Message</option>
+ <option value="user">Private Message</option>
+ </select>
+ </div>
+ <div class="field">
+ <label>Phone / Group ID</label>
+ <input v-model="phone" type="text" placeholder="6289..."
+ aria-label="phone">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
+ </div>
+ <div class="field">
+ <label>Reply Message ID</label>
+ <input v-model="reply_id" type="text"
+ placeholder="Optional: 57D29F74B7FC62F57D8AC2C840279B5B/3EB0288F008D32FCD0A424"
+ aria-label="reply_id">
+ </div>
+ <div class="field">
+ <label>Message</label>
+ <textarea v-model="text" placeholder="Hello this is message text"
+ aria-label="message"></textarea>
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <div class="ui approve positive right labeled icon button" :class="{'loading': this.loading}"
+ @click="handleSubmit">
+ Send
+ <i class="send icon"></i>
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/components/SendPoll.js b/src/views/components/SendPoll.js
index d3fd6837..5ef2ce70 100644
--- a/src/views/components/SendPoll.js
+++ b/src/views/components/SendPoll.js
@@ -3,76 +3,73 @@ export default {
name: 'SendPoll',
data() {
return {
- poll_phone: '',
- poll_type: 'user',
- poll_loading: false,
- poll_question: '',
- poll_options: ['', ''],
- poll_max_vote: 1,
+ phone: '',
+ type: 'user',
+ loading: false,
+ question: '',
+ options: ['', ''],
+ max_vote: 1,
}
},
computed: {
- poll_phone_id() {
- return this.poll_type === 'user' ? `${this.poll_phone}@${window.TYPEUSER}` : `${this.poll_phone}@${window.TYPEGROUP}`
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
}
},
methods: {
- sendPollModal() {
+ openModal() {
$('#modalSendPoll').modal({
onApprove: function () {
return false;
}
}).modal('show');
},
- async sendPollProcess() {
+ async handleSubmit() {
try {
- let response = await this.sendPollApi()
+ let response = await this.submitApi()
window.showSuccessInfo(response)
$('#modalSendPoll').modal('hide');
} catch (err) {
window.showErrorInfo(err)
}
},
- sendPollApi() {
- return new Promise(async (resolve, reject) => {
- try {
- this.poll_loading = true;
- const payload = {
- phone: this.poll_phone_id,
- question: this.poll_question,
- max_answer: this.poll_max_vote,
- options: this.poll_options
- }
- let response = await window.http.post(`/send/poll`, payload)
- this.sendPollReset();
- resolve(response.data.message)
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- } finally {
- this.poll_loading = false;
+ async submitApi() {
+ this.loading = true;
+ try {
+ const payload = {
+ phone: this.phone_id,
+ question: this.question,
+ max_answer: this.max_vote,
+ options: this.options
+ }
+ const response = await window.http.post(`/send/poll`, payload)
+ this.handleReset();
+ return response.data.message;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
}
- })
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
},
- sendPollReset() {
- this.poll_phone = '';
- this.poll_type = 'user';
- this.poll_question = '';
- this.poll_options = ['', ''];
- this.poll_max_vote = 1;
+ handleReset() {
+ this.phone = '';
+ this.type = 'user';
+ this.question = '';
+ this.options = ['', ''];
+ this.max_vote = 1;
},
- addPollOption() {
- this.poll_options.push('')
+ addOption() {
+ this.options.push('')
},
- deletePollOption(index) {
- this.poll_options.splice(index, 1)
+ deleteOption(index) {
+ this.options.splice(index, 1)
}
},
template: `
- <div class="blue card" @click="sendPollModal()" style="cursor: pointer">
+ <div class="blue card" @click="openModal()" style="cursor: pointer">
<div class="content">
<a class="ui blue right ribbon label">Send</a>
<div class="header">Send Poll</div>
@@ -92,34 +89,34 @@ export default {
<form class="ui form">
<div class="field">
<label>Type</label>
- <select name="poll_type" v-model="poll_type" aria-label="type">
+ <select name="type" v-model="type" aria-label="type">
<option value="group">Group Message</option>
<option value="user">Private Message</option>
</select>
</div>
<div class="field">
<label>Phone / Group ID</label>
- <input v-model="poll_phone" type="text" placeholder="6289..."
+ <input v-model="phone" type="text" placeholder="6289..."
aria-label="phone">
- <input :value="poll_phone_id" disabled aria-label="whatsapp_id">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
</div>
<div class="field">
<label>Question</label>
- <input v-model="poll_question" type="text" placeholder="Please enter question"
+ <input v-model="question" type="text" placeholder="Please enter question"
aria-label="poll question">
</div>
<div class="field">
<label>Options</label>
<div style="display: flex; flex-direction: column; gap: 5px">
- <div class="ui action input" :key="index" v-for="(option, index) in poll_options">
- <input type="text" placeholder="Option..." v-model="poll_options[index]"
+ <div class="ui action input" :key="index" v-for="(option, index) in options">
+ <input type="text" placeholder="Option..." v-model="options[index]"
aria-label="poll option">
- <button class="ui button" @click="deletePollOption(index)" type="button">
+ <button class="ui button" @click="deleteOption(index)" type="button">
<i class="minus circle icon"></i>
</button>
</div>
<div class="field">
- <button class="mini ui primary button" @click="addPollOption" type="button">
+ <button class="mini ui primary button" @click="addOption" type="button">
<i class="plus icon"></i> Option
</button>
</div>
@@ -127,14 +124,14 @@ export default {
</div>
<div class="field">
<label>Max Vote</label>
- <input v-model="poll_max_vote" type="number" placeholder="Max Vote"
+ <input v-model="max_vote" type="number" placeholder="Max Vote"
aria-label="poll max votes" min="0">
</div>
</form>
</div>
<div class="actions">
- <div class="ui approve positive right labeled icon button" :class="{'loading': this.poll_loading}"
- @click="sendPollProcess" type="button">
+ <div class="ui approve positive right labeled icon button" :class="{'loading': this.loading}"
+ @click="handleSubmit" type="button">
Send
<i class="send icon"></i>
</div>
diff --git a/src/views/components/SendVideo.js b/src/views/components/SendVideo.js
new file mode 100644
index 00000000..5574e502
--- /dev/null
+++ b/src/views/components/SendVideo.js
@@ -0,0 +1,145 @@
+export default {
+ name: 'SendVideo',
+ // define props
+ props: {
+ maxVideoSize: {
+ type: String,
+ required: true,
+ }
+ },
+ data() {
+ return {
+ caption: '',
+ view_once: false,
+ compress: false,
+ type: 'user',
+ phone: '',
+ loading: false,
+ }
+ },
+ computed: {
+ phone_id() {
+ return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}`
+ }
+ },
+ methods: {
+ openModal() {
+ $('#modalSendVideo').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ },
+ async handleSubmit() {
+ try {
+ let response = await this.submitApi()
+ showSuccessInfo(response)
+ $('#modalSendVideo').modal('hide');
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ let payload = new FormData();
+ payload.append("phone", this.phone_id)
+ payload.append("caption", this.caption)
+ payload.append("view_once", this.view_once)
+ payload.append("compress", this.compress)
+ payload.append('video', $("#file_video")[0].files[0])
+ let response = await window.http.post(`/send/video`, payload)
+ this.handleReset();
+ return response.data.message;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
+ },
+ handleReset() {
+ this.caption = '';
+ this.view_once = false;
+ this.compress = false;
+ this.phone = '';
+ this.type = 'user';
+ $("#file_video").val('');
+ },
+ },
+ template: `
+ <div class="blue card" @click="openModal()" style="cursor: pointer">
+ <div class="content">
+ <a class="ui blue right ribbon label">Send</a>
+ <div class="header">Send Video</div>
+ <div class="description">
+ Send video
+ <div class="ui blue horizontal label">mp4</div>
+ up to
+ <div class="ui blue horizontal label">{{ maxVideoSize }}</div>
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal SendVideo -->
+ <div class="ui small modal" id="modalSendVideo">
+ <i class="close icon"></i>
+ <div class="header">
+ Send Video
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <div class="field">
+ <label>Type</label>
+ <select name="type" v-model="type" aria-label="type">
+ <option value="group">Group Message</option>
+ <option value="user">Private Message</option>
+ </select>
+ </div>
+ <div class="field">
+ <label>Phone / Group ID</label>
+ <input v-model="phone" type="text" placeholder="6289..."
+ aria-label="phone">
+ <input :value="phone_id" disabled aria-label="whatsapp_id">
+ </div>
+ <div class="field">
+ <label>Caption</label>
+ <textarea v-model="caption" placeholder="Type some caption (optional)..."
+ aria-label="caption"></textarea>
+ </div>
+ <div class="field">
+ <label>View Once</label>
+ <div class="ui toggle checkbox">
+ <input type="checkbox" aria-label="view once" v-model="view_once">
+ <label>Check for enable one time view</label>
+ </div>
+ </div>
+ <div class="field">
+ <label>Compress</label>
+ <div class="ui toggle checkbox">
+ <input type="checkbox" aria-label="compress" v-model="compress">
+ <label>Check for compressing video to smaller size</label>
+ </div>
+ </div>
+ <div class="field" style="padding-bottom: 30px">
+ <label>Video</label>
+ <input type="file" style="display: none" accept="video/*" id="file_video">
+ <label for="file_video" class="ui positive medium green left floated button" style="color: white">
+ <i class="ui upload icon"></i>
+ Upload video
+ </label>
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <div class="ui approve positive right labeled icon button" :class="{'loading': this.loading}"
+ @click="handleSubmit">
+ Send
+ <i class="send icon"></i>
+ </div>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/index.html b/src/views/index.html
index 8aef03fe..08236d0b 100644
--- a/src/views/index.html
+++ b/src/views/index.html
@@ -12,7 +12,7 @@
<script src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.11.4/js/dataTables.semanticui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.8/semantic.min.js"></script>
- <script src="https://unpkg.com/vue@3"></script>
+ <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://unpkg.com/[email protected]/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
<title>Whatsapp API Multi Device {{ .AppVersion }}</title>
@@ -25,7 +25,7 @@
</head>
<body>
<div class="ui container" id="app">
- <h1 class="ui header center aligned">[[ app_name ]]</h1>
+ <h1 class="ui header center aligned">Whatsapp API Multi Device ({{ .AppVersion }})</h1>
<div class="ui success message" v-if="connected_devices != null">
<div class="header">
@@ -41,31 +41,9 @@
</div>
<div class="ui three column stackable grid cards">
- <div class="green card" @click="loginModal" style="cursor: pointer">
- <div class="content">
- <div class="header">Login</div>
- <div class="description">
- Scan your QRCode and you can use all this API feature
- </div>
- </div>
- </div>
- <div class="green card" @click="logoutProcess" style="cursor: pointer">
- <div class="content">
- <div class="header">Logout</div>
- <div class="description">
- Remove your login session in application
- </div>
- </div>
- </div>
- <div class="green card" @click="reconnectProcess" style="cursor: pointer">
- <div class="content">
- <div class="header">Reconnect</div>
- <div class="description">
- Reconnect to whatsapp server, please do this if your api doesn't work or your application is down or
- restart
- </div>
- </div>
- </div>
+ <app-login></app-login>
+ <app-logout @reload-devices="handleReloadDevice"></app-logout>
+ <app-reconnect @reload-devices="handleReloadDevice"></app-reconnect>
</div>
<div class="ui horizontal divider">
@@ -73,76 +51,15 @@
</div>
<div class="ui three column doubling grid cards">
- <div class="blue card" @click="sendMessageModal()" style="cursor: pointer">
- <div class="content">
- <a class="ui blue right ribbon label">Send</a>
- <div class="header">Send Message</div>
- <div class="description">
- Send any message to user or group
- </div>
- </div>
- </div>
- <div class="blue card" @click="sendImageModal()" style="cursor:pointer;">
- <div class="content">
- <a class="ui blue right ribbon label">Send</a>
- <div class="header">Send Image</div>
- <div class="description">
- Send image with
- <div class="ui blue horizontal label">jpg/jpeg/png</div>
- type
- </div>
- </div>
- </div>
- <div class="blue card" @click="sendFileModal()" style="cursor: pointer">
- <div class="content">
- <a class="ui blue right ribbon label">Send</a>
- <div class="header">Send File</div>
- <div class="description">
- Send any file up to
- <div class="ui blue horizontal label">{{ .MaxFileSize }}</div>
- </div>
- </div>
- </div>
- <div class="blue card" @click="sendVideoModal()" style="cursor: pointer">
- <div class="content">
- <a class="ui blue right ribbon label">Send</a>
- <div class="header">Send Video</div>
- <div class="description">
- Send video
- <div class="ui blue horizontal label">mp4</div>
- up to
- <div class="ui blue horizontal label">{{ .MaxVideoSize }}</div>
- </div>
- </div>
- </div>
- <div class="blue card" @click="sendContactModal()" style="cursor: pointer">
- <div class="content">
- <a class="ui blue right ribbon label">Send</a>
- <div class="header">Send Contact</div>
- <div class="description">
- Send contact to user or group
- </div>
- </div>
- </div>
- <div class="blue card" @click="sendLocationModal()" style="cursor: pointer">
- <div class="content">
- <a class="ui blue right ribbon label">Send</a>
- <div class="header">Send Location</div>
- <div class="description">
- Send location to user or group
- </div>
- </div>
- </div>
- <div class="blue card" @click="sendAudioModal()" style="cursor: pointer">
- <div class="content">
- <a class="ui blue right ribbon label">Send</a>
- <div class="header">Send Audio</div>
- <div class="description">
- Send audio to user or group
- </div>
- </div>
- </div>
+ <send-message></send-message>
+ <send-image></send-image>
+ <send-file max-file-size="{{ .MaxFileSize }}"></send-file>
+ <send-video max-video-size="{{ .MaxVideoSize }}"></send-video>
+ <send-contact></send-contact>
+ <send-location></send-location>
+
+ <send-audio></send-audio>
<send-poll></send-poll>
</div>
@@ -151,25 +68,8 @@
</div>
<div class="ui three column doubling grid cards">
- <div class="red card" @click="messageRevokeModal()" style="cursor: pointer">
- <div class="content">
- <a class="ui red right ribbon label">Message</a>
- <div class="header">Revoke Message</div>
- <div class="description">
- Revoke any message in private or group chat
- </div>
- </div>
- </div>
- <div class="red card" @click="messageReactModal()" style="cursor: pointer">
- <div class="content">
- <a class="ui red right ribbon label">Message</a>
- <div class="header">React Message</div>
- <div class="description">
- React any message in private or group chat
- </div>
- </div>
- </div>
-
+ <message-revoke></message-revoke>
+ <message-react></message-react>
<message-update></message-update>
</div>
@@ -178,619 +78,12 @@
</div>
<div class="ui four column doubling grid cards">
- <div class="green card" @click="avatarModal" style="cursor: pointer;">
- <div class="content">
- <div class="header">Avatar</div>
- <div class="description">
- You can search someone avatar by phone
- </div>
- </div>
- </div>
- <div class="green card" @click="infoModal" style="cursor: pointer;">
- <div class="content">
- <div class="header">User Info</div>
- <div class="description">
- You can search someone user info by phone
- </div>
- </div>
- </div>
- <div class="green card" @click="groupModal" style="cursor: pointer">
- <div class="content">
- <div class="header">My List Groups</div>
- <div class="description">
- Display all groups you joined
- </div>
- </div>
- </div>
- <div class="green card" @click="privacyModal" style="cursor: pointer">
- <div class="content">
- <div class="header">My Privacy Setting</div>
- <div class="description">
- Get your privacy settings
- </div>
- </div>
- </div>
- </div>
-
-
- <!-- Modal Login -->
- <div class="ui small modal" id="modalLogin">
- <i class="close icon"></i>
- <div class="header">
- Login Whatsapp
- </div>
- <div class="image content">
- <div class="ui medium image">
- <img :src="login_link" alt="qrCodeLogin">
- </div>
- <div class="description">
- <div class="ui header">Please scan to connect</div>
- <p>Open Setting > Linked Devices > Link Device</p>
- <div style="padding-top: 50px;">
- <i>Refresh QR Code in [[ login_duration_sec ]] seconds to avoid link expiration</i>
- </div>
- </div>
- </div>
- <div class="actions">
- <div class="ui approve positive right labeled icon button" @click="loginApiGetQrCode">
- Refresh QR Code
- <i class="refresh icon"></i>
- </div>
- </div>
- </div>
-
- <!-- Modal SendMessage -->
- <div class="ui small modal" id="modalSendMessage">
- <i class="close icon"></i>
- <div class="header">
- Send Message
- </div>
- <div class="content">
- <form class="ui form">
- <div class="field">
- <label>Type</label>
- <select name="message_type" v-model="message_type" aria-label="type">
- <option value="group">Group Message</option>
- <option value="user">Private Message</option>
- </select>
- </div>
- <div class="field">
- <label>Phone / Group ID</label>
- <input v-model="message_phone" type="text" placeholder="6289..."
- aria-label="phone">
- <input :value="message_phone_id" disabled aria-label="whatsapp_id">
- </div>
- <div class="field">
- <label>Reply Message ID</label>
- <input v-model="message_reply_message_id" type="text"
- placeholder="Optional: 57D29F74B7FC62F57D8AC2C840279B5B/3EB0288F008D32FCD0A424"
- aria-label="reply_message_id">
- </div>
- <div class="field">
- <label>Message</label>
- <textarea v-model="message_text" type="text" placeholder="Hello this is message text"
- aria-label="message"></textarea>
- </div>
- </form>
- </div>
- <div class="actions">
- <div class="ui approve positive right labeled icon button" :class="{'loading': this.message_loading}"
- @click="sendMessageProcess">
- Send
- <i class="send icon"></i>
- </div>
- </div>
- </div>
-
- <!-- Modal SendImage -->
- <div class="ui small modal" id="modalSendImage">
- <i class="close icon"></i>
- <div class="header">
- Send Image
- </div>
- <div class="content">
- <form class="ui form">
- <div class="field">
- <label>Type</label>
- <select name="image_type" v-model="image_type" aria-label="type">
- <option value="group">Group Message</option>
- <option value="user">Private Message</option>
- </select>
- </div>
- <div class="field">
- <label>Phone / Group ID</label>
- <input v-model="image_phone" type="text" placeholder="6289..."
- aria-label="phone">
- <input :value="image_phone_id" disabled aria-label="whatsapp_id">
- </div>
- <div class="field">
- <label>Caption</label>
- <textarea v-model="image_caption" type="text" placeholder="Hello this is image caption"
- aria-label="caption"></textarea>
- </div>
- <div class="field">
- <label>View Once</label>
- <div class="ui toggle checkbox">
- <input type="checkbox" aria-label="view once" v-model="image_view_once">
- <label>Check for enable one time view</label>
- </div>
- </div>
- <div class="field">
- <label>Compress</label>
- <div class="ui toggle checkbox">
- <input type="checkbox" aria-label="compress" v-model="image_compress">
- <label>Check for compressing image to smaller size</label>
- </div>
- </div>
- <div class="field" style="padding-bottom: 30px">
- <label>Image</label>
- <input type="file" class="inputfile" id="image_file" style="display: none"
- accept="image/png,image/jpg,image/jpeg"/>
- <label for="image_file" class="ui positive medium green left floated button" style="color: white">
- <i class="ui upload icon"></i>
- Upload image
- </label>
- </div>
- </form>
- </div>
- <div class="actions">
- <div class="ui approve positive right labeled icon button" :class="{'loading': this.image_loading}"
- @click="sendImageProcess">
- Send
- <i class="send icon"></i>
- </div>
- </div>
- </div>
-
- <!-- Modal SendAudio -->
- <div class="ui small modal" id="modalSendAudio">
- <i class="close icon"></i>
- <div class="header">
- Send Audio
- </div>
- <div class="content">
- <form class="ui form">
- <div class="field">
- <label>Type</label>
- <select name="audio_type" v-model="audio_type" aria-label="type">
- <option value="group">Group Message</option>
- <option value="user">Private Message</option>
- </select>
- </div>
- <div class="field">
- <label>Phone / Group ID</label>
- <input v-model="audio_phone" type="text" placeholder="6289..."
- aria-label="phone">
- <input :value="audio_phone_id" disabled aria-label="whatsapp_id">
- </div>
- <div class="field" style="padding-bottom: 30px">
- <label>Audio</label>
- <input type="file" class="inputfile" id="audio_file" style="display: none"
- accept="audio/*"/>
- <label for="audio_file" class="ui positive medium green left floated button" style="color: white">
- <i class="ui upload icon"></i>
- Upload Audio
- </label>
- </div>
- </form>
- </div>
- <div class="actions">
- <div class="ui approve positive right labeled icon button" :class="{'loading': this.audio_loading}"
- @click="sendAudioProcess">
- Send
- <i class="send icon"></i>
- </div>
- </div>
- </div>
-
- <!-- Modal SendFile -->
- <div class="ui small modal" id="modalSendFile">
- <i class="close icon"></i>
- <div class="header">
- Send File
- </div>
- <div class="content">
- <form class="ui form">
- <div class="field">
- <label>Type</label>
- <select name="file_type" v-model="file_type" aria-label="type">
- <option value="group">Group Message</option>
- <option value="user">Private Message</option>
- </select>
- </div>
- <div class="field">
- <label>Phone / Group ID</label>
- <input v-model="file_phone" type="text" placeholder="6289..."
- aria-label="phone">
- <input :value="file_phone_id" disabled aria-label="whatsapp_id">
- </div>
- <div class="field">
- <label>Caption</label>
- <textarea v-model="file_caption" type="text" placeholder="Type some caption (optional)..."
- aria-label="caption"></textarea>
- </div>
- <div class="field" style="padding-bottom: 30px">
- <label>File</label>
- <input type="file" class="inputfile" id="file_file" style="display: none"/>
- <label for="file_file" class="ui positive medium green left floated button" style="color: white">
- <i class="ui upload icon"></i>
- Upload file
- </label>
- </div>
- </form>
- </div>
- <div class="actions">
- <div class="ui approve positive right labeled icon button" :class="{'loading': this.file_loading}"
- @click="sendFileProcess">
- Send
- <i class="send icon"></i>
- </div>
- </div>
- </div>
-
- <!-- Modal SendVideo -->
- <div class="ui small modal" id="modalSendVideo">
- <i class="close icon"></i>
- <div class="header">
- Send Video
- </div>
- <div class="content">
- <form class="ui form">
- <div class="field">
- <label>Type</label>
- <select name="video_type" v-model="video_type" aria-label="type">
- <option value="group">Group Message</option>
- <option value="user">Private Message</option>
- </select>
- </div>
- <div class="field">
- <label>Phone / Group ID</label>
- <input v-model="video_phone" type="text" placeholder="6289..."
- aria-label="phone">
- <input :value="video_phone_id" disabled aria-label="whatsapp_id">
- </div>
- <div class="field">
- <label>Caption</label>
- <textarea v-model="video_caption" type="text" placeholder="Type some caption (optional)..."
- aria-label="caption"></textarea>
- </div>
- <div class="field">
- <label>View Once</label>
- <div class="ui toggle checkbox">
- <input type="checkbox" aria-label="view once" v-model="video_view_once">
- <label>Check for enable one time view</label>
- </div>
- </div>
- <div class="field">
- <label>Compress</label>
- <div class="ui toggle checkbox">
- <input type="checkbox" aria-label="compress" v-model="video_compress">
- <label>Check for compressing video to smaller size</label>
- </div>
- </div>
- <div class="field" style="padding-bottom: 30px">
- <label>Video</label>
- <input type="file" class="inputfile" id="video_file" style="display: none" accept="video/*"/>
- <label for="video_file" class="ui positive medium green left floated button" style="color: white">
- <i class="ui upload icon"></i>
- Upload video
- </label>
- </div>
- </form>
- </div>
- <div class="actions">
- <div class="ui approve positive right labeled icon button" :class="{'loading': this.video_loading}"
- @click="sendVideoProcess">
- Send
- <i class="send icon"></i>
- </div>
- </div>
- </div>
-
- <!-- Modal SendContact -->
- <div class="ui small modal" id="modalSendContact">
- <i class="close icon"></i>
- <div class="header">
- Send Contact
- </div>
- <div class="content">
- <form class="ui form">
- <div class="field">
- <label>Type</label>
- <select name="contact_type" v-model="contact_type" aria-label="type">
- <option value="group">Group Message</option>
- <option value="user">Private Message</option>
- </select>
- </div>
- <div class="field">
- <label>Phone / Group ID</label>
- <input v-model="contact_phone" type="text" placeholder="6289..."
- aria-label="phone">
- <input :value="contact_phone_id" disabled aria-label="whatsapp_id">
- </div>
- <div class="field">
- <label>Contact Name</label>
- <input v-model="contact_card_name" type="text" placeholder="Please enter contact name"
- aria-label="contact name">
- </div>
- <div class="field">
- <label>Contact Phone</label>
- <input v-model="contact_card_phone" type="text" placeholder="Please enter contact phone"
- aria-label="contact phone">
- </div>
- </form>
- </div>
- <div class="actions">
- <div class="ui approve positive right labeled icon button" :class="{'loading': this.contact_loading}"
- @click="sendContactProcess">
- Send
- <i class="send icon"></i>
- </div>
- </div>
- </div>
-
- <!-- Modal SendLocation -->
- <div class="ui small modal" id="modalSendLocation">
- <i class="close icon"></i>
- <div class="header">
- Send Location
- </div>
- <div class="content">
- <form class="ui form">
- <div class="field">
- <label>Type</label>
- <select name="location_type" v-model="location_type" aria-label="type">
- <option value="group">Group Message</option>
- <option value="user">Private Message</option>
- </select>
- </div>
- <div class="field">
- <label>Phone / Group ID</label>
- <input v-model="location_phone" type="text" placeholder="6289..."
- aria-label="phone">
- <input :value="location_phone_id" disabled aria-label="whatsapp_id">
- </div>
- <div class="field">
- <label>Location Latitude</label>
- <input v-model="location_latitude" type="text" placeholder="Please enter latitude"
- aria-label="latitude">
- </div>
- <div class="field">
- <label>Location Longitude</label>
- <input v-model="location_longitude" type="text" placeholder="Please enter longitude"
- aria-label="longitude">
- </div>
- </form>
- </div>
- <div class="actions">
- <div class="ui approve positive right labeled icon button" :class="{'loading': this.location_loading}"
- @click="sendLocationProcess">
- Send
- <i class="send icon"></i>
- </div>
- </div>
- </div>
-
- <!-- Modal MessageRevoke -->
- <div class="ui small modal" id="modalMessageRevoke">
- <i class="close icon"></i>
- <div class="header">
- Revoke Message
- </div>
- <div class="content">
- <form class="ui form">
- <div class="field">
- <label>Type</label>
- <select name="revoke_type" v-model="revoke_type" aria-label="type">
- <option value="group">Group Message</option>
- <option value="user">Private Message</option>
- </select>
- </div>
- <div class="field">
- <label>Phone / Group ID</label>
- <input v-model="revoke_phone" type="text" placeholder="6289..."
- aria-label="phone">
- <input :value="revoke_phone_id" disabled aria-label="whatsapp_id">
- </div>
- <div class="field">
- <label>Revoke Message ID</label>
- <input v-model="revoke_message_id" type="text" placeholder="Please enter your message id"
- aria-label="message id">
- </div>
- </form>
- </div>
- <div class="actions">
- <div class="ui approve positive right labeled icon button" :class="{'loading': this.revoke_loading}"
- @click="messageRevokeProcess">
- Send
- <i class="send icon"></i>
- </div>
- </div>
+ <account-avatar></account-avatar>
+ <account-user-info></account-user-info>
+ <account-group></account-group>
+ <account-privacy></account-privacy>
</div>
- <!-- Modal MessageReaction -->
- <div class="ui small modal" id="modalMessageReaction">
- <i class="close icon"></i>
- <div class="header">
- React Message
- </div>
- <div class="content">
- <form class="ui form">
- <div class="field">
- <label>Type</label>
- <select name="react_type" v-model="react_type" aria-label="type">
- <option value="group">Group Message</option>
- <option value="user">Private Message</option>
- </select>
- </div>
- <div class="field">
- <label>Phone / Group ID</label>
- <input v-model="react_phone" type="text" placeholder="6289..."
- aria-label="phone">
- <input :value="react_phone_id" disabled aria-label="whatsapp_id">
- </div>
- <div class="field">
- <label>Message ID</label>
- <input v-model="react_message_id" type="text" placeholder="Please enter your message id"
- aria-label="message id">
- </div>
- <div class="field">
- <label>Emoji</label>
- <input v-model="react_emoji" type="text" placeholder="Please enter emoji"
- aria-label="message id">
- </div>
- </form>
- </div>
- <div class="actions">
- <div class="ui approve positive right labeled icon button" :class="{'loading': this.react_loading}"
- @click="messageReactProcess">
- Send
- <i class="send icon"></i>
- </div>
- </div>
- </div>
-
- <!-- Modal UserGroup -->
- <div class="ui small modal" id="modalUserGroup">
- <i class="close icon"></i>
- <div class="header">
- My Group List
- </div>
- <div class="content">
- <table class="ui celled table" id="user_groups_table">
- <thead>
- <tr>
- <th>Group ID</th>
- <th>Name</th>
- <th>Participants</th>
- <th>Created At</th>
- <th>Action</th>
- </tr>
- </thead>
- <tbody v-if="data_groups != null">
- <tr v-for="g in data_groups">
- <td>[[ g.JID.split('@')[0] ]]</td>
- <td>[[ g.Name ]]</td>
- <td>[[ g.Participants.length ]]</td>
- <td>[[ formatDate(g.GroupCreated) ]]</td>
- <td>
- <button class="ui red tiny button" @click="handleLeaveGroup(g.JID)">Leave</button>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
-
- <!-- Modal UserPrivacy -->
- <div class="ui small modal" id="modalUserPrivacy">
- <i class="close icon"></i>
- <div class="header">
- My Privacy
- </div>
- <div class="content">
- <ol v-if="data_privacy != null">
- <li>Who can add Group : <b>[[ data_privacy.group_add ]]</b></li>
- <li>Who can see my Last Seen : <b>[[ data_privacy.last_seen ]]</b></li>
- <li>Who can see my Status : <b>[[ data_privacy.status ]]</b></li>
- <li>Who can see my Profile : <b>[[ data_privacy.profile ]]</b></li>
- <li>Read Receipts : <b>[[ data_privacy.read_receipts ]]</b></li>
- </ol>
- </div>
- </div>
-
- <!-- Modal UserAvatar -->
- <div class="ui small modal" id="modalUserAvatar">
- <i class="close icon"></i>
- <div class="header">
- Search User Avatar
- </div>
- <div class="content">
- <form class="ui form">
- <div class="field">
- <label>Type</label>
- <select name="avatar_type" v-model="avatar_type" aria-label="type">
- <option value="group">Group Message</option>
- <option value="user">Private Message</option>
- </select>
- </div>
- <div class="field">
- <label>Phone</label>
- <input v-model="avatar_phone" type="text" placeholder="6289..."
- aria-label="phone">
- <input :value="avatar_phone_id" disabled aria-label="whatsapp_id">
- </div>
-
- <div class="field">
- <label>Preview</label>
- <div class="ui toggle checkbox">
- <input type="checkbox" aria-label="compress" v-model="avatar_is_preview">
- <label>Check for small size image</label>
- </div>
- </div>
-
- <div class="field">
- <label>Community</label>
- <div class="ui toggle checkbox">
- <input type="checkbox" aria-label="compress" v-model="avatar_is_community">
- <label>Check is it's community image</label>
- </div>
- </div>
-
- <button type="button" class="ui primary button" :class="{'loading': avatar_loading}"
- @click="avatarProcess">
- Search
- </button>
- </form>
-
- <div v-if="avatar_image != null" class="center">
- <img :src="avatar_image" alt="profile picture" style="padding-top: 10px; max-height: 200px">
- </div>
- </div>
- </div>
-
- <!-- Modal UserInfo -->
- <div class="ui small modal" id="modalUserInfo">
- <i class="close icon"></i>
- <div class="header">
- Search User Information
- </div>
- <div class="content">
- <form class="ui form">
- <div class="field">
- <label>Type</label>
- <select name="info_type" v-model="info_type" aria-label="type">
- <option value="user">Private Message</option>
- </select>
- </div>
- <div class="field">
- <label>Phone</label>
- <input v-model="info_phone" type="text" placeholder="6289..."
- aria-label="phone">
- <input :value="info_phone_id" disabled aria-label="whatsapp_id">
- </div>
-
- <button type="button" class="ui primary button" :class="{'loading': info_loading}"
- @click="infoProcess">
- Search
- </button>
- </form>
-
- <div v-if="info_devices.length > 0" class="center">
- <ol>
- <li>Nama: [[ info_name ]]</li>
- <li>Status: [[ info_status ]]</li>
- <li>Device:
- <ul>
- <li v-for="d in info_devices">
- [[ d.Device ]]
- </li>
- </ul>
- </li>
- </ol>
- </div>
- </div>
- </div>
</div>
<script>
window.TYPEGROUP = "g.us";
@@ -822,8 +115,24 @@
{{ end }}
</script>
<script type="module">
+ import AppLogin from "./components/AppLogin.js";
+ import AppLogout from "./components/AppLogout.js";
+ import AppReconnect from "./components/AppReconnect.js";
+ import SendMessage from "./components/SendMessage.js";
+ import SendImage from "./components/SendImage.js";
+ import SendFile from "./components/SendFile.js";
+ import SendVideo from "./components/SendVideo.js";
+ import SendContact from "./components/SendContact.js";
+ import SendLocation from "./components/SendLocation.js";
+ import SendAudio from "./components/SendAudio.js";
import SendPoll from "./components/SendPoll.js";
import MessageUpdate from "./components/MessageUpdate.js";
+ import MessageReact from "./components/MessageReact.js";
+ import MessageRevoke from "./components/MessageRevoke.js";
+ import AccountAvatar from "./components/AccountAvatar.js";
+ import AccountUserInfo from "./components/AccountUserInfo.js";
+ import AccountGroup from "./components/AccountGroup.js";
+ import AccountPrivacy from "./components/AccountPrivacy.js";
const showErrorInfo = (message) => {
$('body').toast({
@@ -844,918 +153,23 @@
});
}
- const login = {
- data() {
- return {
- login_link: '',
- login_duration_sec: 0,
- autoUpdateQRCode: null,
- }
- },
- methods: {
- async loginModal() {
- try {
- await this.loginApiGetQrCode();
- $('#modalLogin').modal({
- onApprove: function () {
- return false;
- }
- }).modal('show');
- } catch (err) {
- showErrorInfo(err)
- }
- },
- loginApiGetQrCode() {
- return new Promise(async (resolve, reject) => {
- try {
- let response = await http.get(`/app/login`)
- let results = response.data.results;
- this.login_link = results.qr_link;
- this.login_duration_sec = results.qr_duration;
- resolve()
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- }
- })
- }
- }
- }
-
- const logout = {
- methods: {
- async logoutProcess() {
- try {
- await this.logoutApi()
- showSuccessInfo("Logout success")
-
- // fetch devices
- this.app_ws.send(JSON.stringify({"code": "FETCH_DEVICES"}))
- } catch (err) {
- showErrorInfo(err)
- }
- },
-
- logoutApi() {
- return new Promise(async (resolve, reject) => {
- try {
- await http.get(`/app/logout`)
- resolve()
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- }
- })
- }
- }
- }
-
- const reconnect = {
- methods: {
- async reconnectProcess() {
- try {
- await this.reconnectApi()
- showSuccessInfo("Reconnect success")
- // fetch devices
- this.app_ws.send(JSON.stringify({"code": "FETCH_DEVICES"}))
- } catch (err) {
- showErrorInfo(err)
- }
- },
-
- reconnectApi() {
- return new Promise(async (resolve, reject) => {
- try {
- await http.get(`/app/reconnect`)
- resolve()
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- }
- })
- }
- }
- }
-
- const sendMessage = {
- data() {
- return {
- message_type: 'user',
- message_phone: '',
- message_text: '',
- message_reply_message_id: '',
- message_loading: false,
- }
- },
- computed: {
- message_phone_id() {
- return this.message_type === 'user' ? `${this.message_phone}@${this.type_user}` : `${this.message_phone}@${this.type_group}`
- }
- },
- methods: {
- sendMessageModal() {
- $('#modalSendMessage').modal({
- onApprove: function () {
- return false;
- }
- }).modal('show');
- },
- async sendMessageProcess() {
- try {
- let response = await this.sendMessageApi()
- showSuccessInfo(response)
- $('#modalSendMessage').modal('hide');
- } catch (err) {
- showErrorInfo(err)
- }
- },
- sendMessageApi() {
- return new Promise(async (resolve, reject) => {
- try {
- this.message_loading = true;
- let payload = new FormData();
- payload.append("phone", this.message_phone_id)
- payload.append("message", this.message_text)
- if (this.message_reply_message_id !== '') {
- payload.append("reply_message_id", this.message_reply_message_id)
- }
- let response = await http.post(`/send/message`, payload)
- this.sendMessageReset();
- resolve(response.data.message)
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- } finally {
- this.message_loading = false;
- }
- })
- },
- sendMessageReset() {
- this.message_phone = '';
- this.message_text = '';
- this.message_type = 'user';
- this.message_reply_message_id = '';
- },
- }
- }
-
- const sendImage = {
- data() {
- return {
- image_phone: '',
- image_view_once: false,
- image_compress: false,
- image_caption: '',
- image_type: 'user',
- image_loading: false,
- }
- },
- computed: {
- image_phone_id() {
- return this.image_type === 'user' ? `${this.image_phone}@${this.type_user}` : `${this.image_phone}@${this.type_group}`
- }
- },
- methods: {
- sendImageModal() {
- $('#modalSendImage').modal({
- onApprove: function () {
- return false;
- }
- }).modal('show');
- },
- async sendImageProcess() {
- try {
- let response = await this.sendImageApi()
- showSuccessInfo(response)
- $('#modalSendImage').modal('hide');
- } catch (err) {
- showErrorInfo(err)
- }
- },
- sendImageApi() {
- return new Promise(async (resolve, reject) => {
- try {
- this.image_loading = true;
- let payload = new FormData();
- payload.append("phone", this.image_phone_id)
- payload.append("view_once", this.image_view_once)
- payload.append("compress", this.image_compress)
- payload.append("caption", this.image_caption)
- payload.append("image", $("#image_file")[0].files[0])
- let response = await http.post(`/send/image`, payload)
- this.sendImageReset();
- resolve(response.data.message)
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- } finally {
- this.image_loading = false;
- }
- })
- },
- sendImageReset() {
- this.image_view_once = false;
- this.image_compress = false;
- this.image_phone = '';
- this.image_caption = '';
- this.image_type = 'user';
- $("#image_file").val('');
- },
- }
- }
-
- const sendFile = {
- data() {
- return {
- file_caption: '',
- file_type: 'user',
- file_phone: '',
- file_loading: false,
- }
- },
- computed: {
- file_phone_id() {
- return this.file_type === 'user' ? `${this.file_phone}@${this.type_user}` : `${this.file_phone}@${this.type_group}`
- }
- },
- methods: {
- sendFileModal() {
- $('#modalSendFile').modal({
- onApprove: function () {
- return false;
- }
- }).modal('show');
- },
- async sendFileProcess() {
- try {
- let response = await this.sendFileApi()
- showSuccessInfo(response)
- $('#modalSendFile').modal('hide');
- } catch (err) {
- showErrorInfo(err)
- }
- },
- sendFileApi() {
- return new Promise(async (resolve, reject) => {
- try {
- this.file_loading = true;
- let payload = new FormData();
- payload.append("caption", this.file_caption)
- payload.append("phone", this.file_phone_id)
- payload.append("file", $("#file_file")[0].files[0])
- let response = await http.post(`/send/file`, payload)
- this.sendFileReset();
- resolve(response.data.message)
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- } finally {
- this.file_loading = false;
- }
- })
- },
- sendFileReset() {
- this.file_caption = '';
- this.file_phone = '';
- this.file_type = 'user';
- $("#file_file").val('');
- },
- }
- }
-
- const sendAudio = {
- data() {
- return {
- audio_phone: '',
- audio_type: 'user',
- audio_loading: false,
- }
- },
- computed: {
- audio_phone_id() {
- return this.audio_type === 'user' ? `${this.audio_phone}@${this.type_user}` : `${this.audio_phone}@${this.type_group}`
- }
- },
- methods: {
- sendAudioModal() {
- $('#modalSendAudio').modal({
- onApprove: function () {
- return false;
- }
- }).modal('show');
- },
- async sendAudioProcess() {
- try {
- let response = await this.sendAudioApi()
- showSuccessInfo(response)
- $('#modalSendAudio').modal('hide');
- } catch (err) {
- showErrorInfo(err)
- }
- },
- sendAudioApi() {
- return new Promise(async (resolve, reject) => {
- try {
- this.audio_loading = true;
- let payload = new FormData();
- payload.append("phone", this.audio_phone_id)
- payload.append("audio", $("#audio_file")[0].files[0])
- let response = await http.post(`/send/audio`, payload)
- this.sendAudioReset();
- resolve(response.data.message)
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- } finally {
- this.audio_loading = false;
- }
- })
- },
- sendAudioReset() {
- this.audio_phone = '';
- this.audio_type = 'user';
- $("#audio_file").val('');
- },
- }
- }
-
- const sendVideo = {
- data() {
- return {
- video_caption: '',
- video_view_once: false,
- video_compress: false,
- video_type: 'user',
- video_phone: '',
- video_loading: false,
- }
- },
- computed: {
- video_phone_id() {
- return this.video_type === 'user' ? `${this.video_phone}@${this.type_user}` : `${this.video_phone}@${this.type_group}`
- }
- },
- methods: {
- sendVideoModal() {
- $('#modalSendVideo').modal({
- onApprove: function () {
- return false;
- }
- }).modal('show');
- },
- async sendVideoProcess() {
- try {
- let response = await this.sendVideoApi()
- showSuccessInfo(response)
- $('#modalSendVideo').modal('hide');
- } catch (err) {
- showErrorInfo(err)
- }
- },
- sendVideoApi() {
- return new Promise(async (resolve, reject) => {
- try {
- this.video_loading = true;
- let payload = new FormData();
- payload.append("phone", this.video_phone_id)
- payload.append("caption", this.video_caption)
- payload.append("view_once", this.video_view_once)
- payload.append("compress", this.video_compress)
- payload.append("video", $("#video_file")[0].files[0])
- let response = await http.post(`/send/video`, payload)
- this.sendVideoReset();
- resolve(response.data.message)
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- } finally {
- this.video_loading = false;
- }
- })
- },
- sendVideoReset() {
- this.video_caption = '';
- this.video_view_once = false;
- this.video_compress = false;
- this.video_phone = '';
- this.video_type = 'user';
- $("#video_file").val('');
- },
- }
- }
-
- const sendContact = {
- data() {
- return {
- contact_type: 'user',
- contact_phone: '',
- contact_card_name: '',
- contact_card_phone: '',
- contact_loading: false,
- }
- },
- computed: {
- contact_phone_id() {
- return this.contact_type === 'user' ? `${this.contact_phone}@${this.type_user}` : `${this.contact_phone}@${this.type_group}`
- }
- },
- methods: {
- sendContactModal() {
- $('#modalSendContact').modal({
- onApprove: function () {
- return false;
- }
- }).modal('show');
- },
- async sendContactProcess() {
- try {
- this.contact_loading = true;
- let response = await this.sendContactApi()
- showSuccessInfo(response)
- $('#modalSendContact').modal('hide');
- } catch (err) {
- showErrorInfo(err)
- } finally {
- this.contact_loading = false;
- }
- },
- sendContactApi() {
- return new Promise(async (resolve, reject) => {
- try {
- let payload = new FormData();
- payload.append("phone", this.contact_phone_id)
- payload.append("contact_name", this.contact_card_name)
- payload.append("contact_phone", this.contact_card_phone)
- let response = await http.post(`/send/contact`, payload)
- this.sendContactReset();
- resolve(response.data.message)
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- }
- })
- },
- sendContactReset() {
- this.contact_phone = '';
- this.contact_card_name = '';
- this.contact_card_phone = '';
- this.contact_type = 'user';
- },
- }
- }
-
- const messageRevoke = {
- data() {
- return {
- revoke_type: 'user',
- revoke_phone: '',
- revoke_message_id: '',
- revoke_loading: false,
- }
- },
- computed: {
- revoke_phone_id() {
- return this.revoke_type === 'user' ? `${this.revoke_phone}@${this.type_user}` : `${this.revoke_phone}@${this.type_group}`
- }
- },
- methods: {
- messageRevokeModal() {
- $('#modalMessageRevoke').modal({
- onApprove: function () {
- return false;
- }
- }).modal('show');
- },
- async messageRevokeProcess() {
- try {
- let response = await this.messageRevokeApi()
- showSuccessInfo(response)
- $('#modalMessageRevoke').modal('hide');
- } catch (err) {
- showErrorInfo(err)
- }
- },
- messageRevokeApi() {
- return new Promise(async (resolve, reject) => {
- try {
- this.revoke_loading = true;
- let payload = new FormData();
- payload.append("phone", this.revoke_phone_id)
- let response = await http.post(`/message/${this.revoke_message_id}/revoke`, payload)
- this.messageRevokeReset();
- resolve(response.data.message)
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- } finally {
- this.revoke_loading = false;
- }
- })
- },
- messageRevokeReset() {
- this.revoke_phone = '';
- this.revoke_message_id = '';
- this.revoke_type = 'user';
- },
- }
- }
-
- const messageReact = {
- data() {
- return {
- react_type: 'user',
- react_phone: '',
- react_message_id: '',
- react_emoji: '',
- react_loading: false,
- }
- },
- computed: {
- react_phone_id() {
- return this.react_type === 'user' ? `${this.react_phone}@${this.type_user}` : `${this.react_phone}@${this.type_group}`
- }
- },
- methods: {
- messageReactModal() {
- $('#modalMessageReaction').modal({
- onApprove: function () {
- return false;
- }
- }).modal('show');
- },
- async messageReactProcess() {
- try {
- let response = await this.messageReactApi()
- showSuccessInfo(response)
- $('#modalMessageReaction').modal('hide');
- } catch (err) {
- showErrorInfo(err)
- }
- },
- messageReactApi() {
- return new Promise(async (resolve, reject) => {
- try {
- this.react_loading = true;
- let payload = new FormData();
- payload.append("phone", this.react_phone_id)
- payload.append("emoji", this.react_emoji)
- let response = await http.post(`/message/${this.react_message_id}/reaction`, payload)
- this.messageReactReset();
- resolve(response.data.message)
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- } finally {
- this.react_loading = false;
- }
- })
- },
- messageReactReset() {
- this.react_phone = '';
- this.react_message_id = '';
- this.react_emoji = '';
- this.react_type = 'user';
- },
- }
- }
-
- const sendLocation = {
- data() {
- return {
- location_type: 'user',
- location_phone: '',
- location_latitude: '',
- location_longitude: '',
- location_loading: false,
- }
- },
- computed: {
- location_phone_id() {
- return this.location_type === 'user' ? `${this.location_phone}@${this.type_user}` : `${this.location_phone}@${this.type_group}`
- }
- },
- methods: {
- sendLocationModal() {
- $('#modalSendLocation').modal({
- onApprove: function () {
- return false;
- }
- }).modal('show');
- },
- async sendLocationProcess() {
- try {
- let response = await this.sendLocationApi()
- showSuccessInfo(response)
- $('#modalSendLocation').modal('hide');
- } catch (err) {
- showErrorInfo(err)
- }
- },
- sendLocationApi() {
- return new Promise(async (resolve, reject) => {
- try {
- this.location_loading = true;
- let payload = new FormData();
- payload.append("phone", this.location_phone_id)
- payload.append("latitude", this.location_latitude)
- payload.append("longitude", this.location_longitude)
- let response = await http.post(`/send/location`, payload)
- this.sendLocationReset();
- resolve(response.data.message)
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- } finally {
- this.location_loading = false;
- }
- })
- },
- sendLocationReset() {
- this.location_phone = '';
- this.location_latitude = '';
- this.location_longitude = '';
- this.location_type = 'user';
- },
- }
- }
-
- const userGroups = {
- data() {
- return {
- data_groups: []
- }
- },
- methods: {
- async groupModal() {
- try {
- this.dtClear()
- await this.groupApi();
- $('#modalUserGroup').modal('show');
- this.dtRebuild()
- showSuccessInfo("Groups fetched")
- } catch (err) {
- showErrorInfo(err)
- }
- },
- dtClear() {
- $('#user_groups_table').DataTable().destroy();
- },
- dtRebuild() {
- $('#user_groups_table').DataTable({
- "pageLength": 100,
- "reloadData": true,
- }).draw();
- },
- async handleLeaveGroup(group_id) {
- try {
- const ok = confirm("Are you sure to leave this group?");
- if (!ok) return;
-
- await this.leaveGroupApi(group_id);
- this.dtClear()
- await this.groupApi();
- this.dtRebuild()
- showSuccessInfo("Group left")
- } catch (err) {
- showErrorInfo(err)
- }
- },
- leaveGroupApi(group_id) {
- return new Promise(async (resolve, reject) => {
- try {
- let payload = new FormData();
- payload.append("group_id", group_id)
- await http.post(`/group/leave`, payload)
- resolve()
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- }
- })
- },
- groupApi() {
- return new Promise(async (resolve, reject) => {
- try {
- let response = await http.get(`/user/my/groups`)
- this.data_groups = response.data.results.data;
- resolve()
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- }
- })
- }
- }
- }
-
- const userPrivacy = {
- data() {
- return {
- data_privacy: null
- }
- },
- methods: {
- async privacyModal() {
- try {
- await this.privacyApi();
- $('#modalUserPrivacy').modal('show');
- showSuccessInfo("Privacy fetched")
- } catch (err) {
- showErrorInfo(err)
- }
- },
- privacyApi() {
- return new Promise(async (resolve, reject) => {
- try {
- let response = await http.get(`/user/my/privacy`)
- this.data_privacy = response.data.results;
- resolve()
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- }
- })
- }
- }
- }
-
- const userAvatar = {
- data() {
- return {
- avatar_type: 'user',
- avatar_phone: '',
- avatar_image: null,
- avatar_loading: false,
- avatar_is_preview: false,
- avatar_is_community: false,
- }
- },
- computed: {
- avatar_phone_id() {
- return this.avatar_type === 'user' ? `${this.avatar_phone}@${this.type_user}` : `${this.avatar_phone}@${this.type_group}`
- }
- },
- methods: {
- async avatarModal() {
- this.avatarReset();
- $('#modalUserAvatar').modal('show');
- },
- async avatarProcess() {
- try {
- this.avatar_loading = true;
- await this.avatarApi();
- this.avatar_loading = false;
- showSuccessInfo("Avatar fetched")
- } catch (err) {
- this.avatar_loading = false;
- showErrorInfo(err)
- }
- },
- avatarApi() {
- return new Promise(async (resolve, reject) => {
- try {
- let response = await http.get(`/user/avatar?phone=${this.avatar_phone_id}&is_preview=${this.avatar_is_preview}&is_community=${this.avatar_is_community}`)
- this.avatar_image = response.data.results.url;
- resolve()
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- }
- })
- },
- avatarReset() {
- this.avatar_phone = '';
- this.avatar_image = null;
- this.avatar_type = 'user';
- }
- }
- }
-
- const userInfo = {
- data() {
- return {
- info_type: 'user',
- info_phone: '',
- //
- info_name: null,
- info_status: null,
- info_devices: [],
- //
- info_loading: false,
- }
- },
-
- computed: {
- info_phone_id() {
- return this.info_type === 'user' ? `${this.info_phone}@${this.type_user}` : `${this.info_phone}@${this.type_group}`
- }
- },
- methods: {
- async infoModal() {
- this.infoReset();
- $('#modalUserInfo').modal('show');
- },
- async infoProcess() {
- try {
- this.info_loading = true;
- await this.infoApi();
- this.info_loading = false;
- showSuccessInfo("Info fetched")
- } catch (err) {
- this.info_loading = false;
- showErrorInfo(err)
- }
- },
- infoApi() {
- return new Promise(async (resolve, reject) => {
- try {
- let response = await http.get(`/user/info?phone=${this.info_phone_id}`)
- this.info_name = response.data.results.verified_name;
- this.info_status = response.data.results.status;
- this.info_devices = response.data.results.devices;
- resolve()
- } catch (error) {
- if (error.response) {
- reject(error.response.data.message)
- } else {
- reject(error.message)
- }
- }
- })
- },
- infoReset() {
- this.info_phone = '';
- this.info_name = null;
- this.info_status = null;
- this.info_devices = [];
- this.info_type = 'user';
- }
- }
- }
-
Vue.createApp({
components: {
- SendPoll,
- MessageUpdate,
+ AppLogin, AppLogout, AppReconnect,
+ SendMessage, SendImage, SendFile, SendVideo, SendContact, SendLocation, SendAudio, SendPoll,
+ MessageUpdate, MessageReact, MessageRevoke,
+ AccountAvatar, AccountUserInfo, AccountGroup, AccountPrivacy
},
delimiters: ['[[', ']]'],
data() {
return {
app_ws: null,
- app_host: {{ .AppHost }},
- app_name: 'Whatsapp API Multi Device ({{ .AppVersion }})',
- is_logged_in: false,
connected_devices: null,
- type_group: "g.us",
- type_user: "s.whatsapp.net"
+ }
+ },
+ methods: {
+ handleReloadDevice() {
+ this.app_ws.send(JSON.stringify({"code": "FETCH_DEVICES"}))
}
},
mounted() {
@@ -1778,7 +192,7 @@
$('#modalLogin').modal('hide');
// fetch devices
- this.app_ws.send(JSON.stringify({"code": "FETCH_DEVICES"}))
+ this.handleReloadDevice()
break;
case 'LIST_DEVICES':
this.connected_devices = message.result
@@ -1791,19 +205,6 @@
console.error('Your browser does not support WebSockets');
}
},
- methods: {
- formatDate: function (value) {
- if (!value) return ''
- const tanggal = moment(value)
- return tanggal.format('LLL');
- }
- },
- mixins: [
- login, logout, reconnect,
- sendMessage, sendImage, sendFile, sendVideo, sendContact, sendLocation, sendAudio,
- messageRevoke, messageReact,
- userGroups, userPrivacy, userAvatar, userInfo
- ]
}).mount('#app')
</script>
</body>