Browse Source
feat: add send poll message (#118)
feat: add send poll message (#118)
* feat: add send poll message * feat: add send poll ui * chore: open api spec and doc * fix: card desc * chore: update homepage imagepull/119/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 370 additions and 108 deletions
-
12.github/workflows/release-linux.yml
-
6.github/workflows/release-mac.yml
-
6.github/workflows/release-windows.yml
-
4docker/golang.Dockerfile
-
57docs/openapi.yaml
-
25readme.md
-
22src/cmd/root.go
-
2src/config/settings.go
-
8src/domains/send/poll.go
-
1src/domains/send/send.go
-
4src/go.mod
-
54src/go.sum
-
19src/internal/rest/send.go
-
13src/main.go
-
20src/services/send.go
-
30src/validations/send_validation.go
-
144src/views/components/SendPoll.js
-
45src/views/index.html
@ -0,0 +1,8 @@ |
|||
package send |
|||
|
|||
type PollRequest struct { |
|||
Phone string `json:"phone" form:"phone"` |
|||
Question string `json:"question" form:"question"` |
|||
Options []string `json:"options" form:"options"` |
|||
MaxAnswer int `json:"max_answer" form:"max_answer"` |
|||
} |
|||
@ -1,7 +1,16 @@ |
|||
package main |
|||
|
|||
import "github.com/aldinokemal/go-whatsapp-web-multidevice/cmd" |
|||
import ( |
|||
"embed" |
|||
"github.com/aldinokemal/go-whatsapp-web-multidevice/cmd" |
|||
) |
|||
|
|||
//go:embed views/index.html
|
|||
var embedViews embed.FS |
|||
|
|||
//go:embed views
|
|||
var embedViewsComponent embed.FS |
|||
|
|||
func main() { |
|||
cmd.Execute() |
|||
cmd.Execute(embedViews, embedViewsComponent) |
|||
} |
|||
@ -0,0 +1,144 @@ |
|||
// export Vue Component
|
|||
export default { |
|||
name: 'SendPoll', |
|||
data() { |
|||
return { |
|||
poll_phone: '', |
|||
poll_type: 'user', |
|||
poll_loading: false, |
|||
poll_question: '', |
|||
poll_options: ['', ''], |
|||
poll_max_vote: 1, |
|||
} |
|||
}, |
|||
computed: { |
|||
poll_phone_id() { |
|||
return this.poll_type === 'user' ? `${this.poll_phone}@${window.TYPEUSER}` : `${this.poll_phone}@${window.TYPEGROUP}` |
|||
} |
|||
}, |
|||
methods: { |
|||
sendPollModal() { |
|||
$('#modalSendPoll').modal({ |
|||
onApprove: function () { |
|||
return false; |
|||
} |
|||
}).modal('show'); |
|||
}, |
|||
async sendPollProcess() { |
|||
try { |
|||
let response = await this.sendPollApi() |
|||
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; |
|||
} |
|||
}) |
|||
}, |
|||
sendPollReset() { |
|||
this.poll_phone = ''; |
|||
this.poll_type = 'user'; |
|||
this.poll_question = ''; |
|||
this.poll_options = ['', '']; |
|||
this.poll_max_vote = 1; |
|||
}, |
|||
addPollOption() { |
|||
this.poll_options.push('') |
|||
}, |
|||
deletePollOption(index) { |
|||
this.poll_options.splice(index, 1) |
|||
} |
|||
}, |
|||
template: `
|
|||
<div class="blue card" @click="sendPollModal()" style="cursor: pointer"> |
|||
<div class="content"> |
|||
<a class="ui blue right ribbon label">Send</a> |
|||
<div class="header">Send Poll</div> |
|||
<div class="description"> |
|||
Send a poll/vote with multiple options |
|||
</div> |
|||
</div> |
|||
</div> |
|||
|
|||
<!-- Modal SendPoll --> |
|||
<div class="ui small modal" id="modalSendPoll"> |
|||
<i class="close icon"></i> |
|||
<div class="header"> |
|||
Send Poll |
|||
</div> |
|||
<div class="content"> |
|||
<form class="ui form"> |
|||
<div class="field"> |
|||
<label>Type</label> |
|||
<select name="poll_type" v-model="poll_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..." |
|||
aria-label="phone"> |
|||
<input :value="poll_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" |
|||
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]" |
|||
aria-label="poll option"> |
|||
<button class="ui button" @click="deletePollOption(index)" type="button"> |
|||
<i class="minus circle icon"></i> |
|||
</button> |
|||
</div> |
|||
<div class="field"> |
|||
<button class="mini ui primary button" @click="addPollOption" type="button"> |
|||
<i class="plus icon"></i> Option |
|||
</button> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="field"> |
|||
<label>Max Vote</label> |
|||
<input v-model="poll_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"> |
|||
Send |
|||
<i class="send icon"></i> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
`
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue