forked from knadh/listmonk
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from pankajsoni19/feature/traffic-split
Feature/traffic split
- Loading branch information
Showing
15 changed files
with
269 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,12 @@ I tagged it to db schema version, and will follow that as semver. Current `5.3.0 | |
- From is moved into smtp, messenger config. | ||
- Sample -> `One <[email protected]>,10,Two <[email protected]>,5`. This will send based on weights assigned. Can be phone number for messenger. | ||
|
||
##### Multi messenger send weighted | ||
|
||
- Can send to multiple channels at once | ||
- traffic can be split based on weights or duplicated on all channels | ||
- For duplicating traffic sliding window limiter counts campaign subscriber triggered not messengers triggered per subscriber. | ||
|
||
##### Per Campaign smtp/messenger | ||
|
||
- In `Settings`>`SMTP` config specify a name. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,14 +81,45 @@ | |
</b-select> | ||
</b-field> | ||
|
||
<b-field :label="$tc('globals.terms.messenger')" label-position="on-border"> | ||
<b-select :placeholder="$tc('globals.terms.messenger')" v-model="form.messenger" name="messenger" | ||
:disabled="!canEdit" required> | ||
<option v-for="m in messengers" :value="m" :key="m"> | ||
{{ m }} | ||
</option> | ||
</b-select> | ||
</b-field> | ||
<div class="columns"> | ||
<div class="column is-4"> | ||
<b-field label="Traffic" label-position="on-border"> | ||
<b-select v-model="form.trafficType" name="run_type" :disabled="!canEdit"> | ||
<option value="split"> | ||
Split | ||
</option> | ||
<option value="duplicate"> | ||
Duplicate | ||
</option> | ||
</b-select> | ||
</b-field> | ||
</div> | ||
</div> | ||
|
||
<div class="columns"> | ||
<div class="column is-12"> | ||
<b-field :label="$tc('globals.terms.messenger')" | ||
label-position="on-border" | ||
message="For spliting data choose integer weights between 1 to 1000. For duplicate all messages are replicated on all selected messengers" | ||
style="border-radius: 5px; border: 1px solid hsl(0, 0%, 86%); padding: 10px;box-shadow: 2px 2px 0 hsl(0, 0%, 96%);" | ||
:disabled="!canEditWindow"> | ||
<div style="display: flex; flex-direction: column;"> | ||
<div v-for="(item, index) in messengers" :key="index" style="display: flex; flex-direction: row; margin-top: 24px;"> | ||
<div style="min-width: 192px;align-content: center;"> | ||
<b-checkbox v-model="selectedStates[item.name]" :disabled="!canEditWindow">{{ item.name }}</b-checkbox> | ||
</div> | ||
<b-field label="Weight" label-position="on-border" :hidden="form.trafficType == 'duplicate'"> | ||
<b-input :maxlength="2" :max="10" :min="1" placeholder="Weight..." style="width: 108px;" v-model="itemValues[item.name]" :disabled="!canEditWindow" /> | ||
</b-field> | ||
</div> | ||
</div> | ||
</b-field> | ||
</div> | ||
</div> | ||
|
||
<div v-if="showError" style="color: red; padding-bottom: 24px;"> | ||
Please select at least one option and provide a weight between 1-1000 | ||
</div> | ||
|
||
<b-field :label="$t('globals.terms.tags')" label-position="on-border"> | ||
<b-taginput v-model="form.tags" name="tags" :disabled="!canEdit" ellipsis icon="tag-outline" | ||
|
@@ -342,6 +373,13 @@ export default Vue.extend({ | |
isAttachModalOpen: false, | ||
activeTab: 'campaign', | ||
// Tracks checkbox states | ||
selectedStates: {}, | ||
// Tracks number input values | ||
itemValues: {}, | ||
showError: false, | ||
submitted: false, | ||
data: {}, | ||
// IDs from ?list_id query param. | ||
|
@@ -354,7 +392,6 @@ export default Vue.extend({ | |
subject: '', | ||
headersStr: '[]', | ||
headers: [], | ||
messenger: 'email', | ||
templateId: 0, | ||
lists: [], | ||
tags: [], | ||
|
@@ -431,8 +468,38 @@ export default Vue.extend({ | |
const archiveStr = `{"email": "[email protected]", "name": "${this.$t('globals.fields.name')}", "attribs": {}}`; | ||
this.form.archiveMetaStr = this.$utils.getPref('campaign.archiveMetaStr') || JSON.stringify(JSON.parse(archiveStr), null, 4); | ||
}, | ||
selectedMessengers() { | ||
const filtered = this.messengers.filter((item) => this.selectedStates[item.name]); | ||
return filtered.map((item) => { | ||
const mrow = { | ||
uuid: item.uuid, | ||
name: item.name, | ||
weight: parseInt(this.itemValues[item.name], 10) || 1, | ||
}; | ||
return mrow; | ||
}); | ||
}, | ||
onSubmit(typ) { | ||
// type -> create | update | test | ||
const messengers = this.selectedMessengers(); | ||
console.log(JSON.stringify(messengers)); | ||
if (messengers.length === 0) { | ||
this.showError = true; | ||
return; | ||
} | ||
if (this.form.trafficType === 'split') { | ||
const outofbound = messengers.find((x) => !x.weight || x.weight < 1 || x.weight > 1000); | ||
if (outofbound) { | ||
this.showError = true; | ||
return; | ||
} | ||
} | ||
// Validate custom JSON headers. | ||
if (this.form.headersStr && this.form.headersStr !== '[]') { | ||
try { | ||
|
@@ -478,6 +545,15 @@ export default Vue.extend({ | |
getCampaign(id) { | ||
return this.$api.getCampaign(id).then((data) => { | ||
this.data = data; | ||
console.log('init', JSON.stringify(this.selectedStates), JSON.stringify(this.itemValues)); | ||
JSON.parse(data.messenger).forEach((m) => { | ||
this.selectedStates[m.name] = true; | ||
this.itemValues[m.name] = m.weight; | ||
}); | ||
console.log('updated', JSON.stringify(this.selectedStates), JSON.stringify(this.itemValues)); | ||
this.form = { | ||
...this.form, | ||
...data, | ||
|
@@ -510,7 +586,7 @@ export default Vue.extend({ | |
name: this.form.name, | ||
subject: this.form.subject, | ||
lists: this.form.lists.map((l) => l.id), | ||
messenger: this.form.messenger, | ||
messenger: JSON.stringify(this.selectedMessengers()), | ||
type: 'regular', | ||
headers: this.form.headers, | ||
tags: this.form.tags, | ||
|
@@ -520,6 +596,7 @@ export default Vue.extend({ | |
altbody: this.form.content.contentType !== 'plain' ? this.form.altbody : null, | ||
subscribers: this.form.testEmails, | ||
media: this.form.media.map((m) => m.id), | ||
traffic_type: this.form.trafficType || 'split', | ||
}; | ||
this.$api.testCampaign(data).then(() => { | ||
|
@@ -535,7 +612,7 @@ export default Vue.extend({ | |
subject: this.form.subject, | ||
lists: this.form.lists.map((l) => l.id), | ||
content_type: 'richtext', | ||
messenger: this.form.messenger, | ||
messenger: JSON.stringify(this.selectedMessengers()), | ||
type: 'regular', | ||
tags: this.form.tags, | ||
send_later: this.form.sendLater, | ||
|
@@ -547,6 +624,7 @@ export default Vue.extend({ | |
sliding_window_rate: this.form.slidingWindowRate || 1, | ||
sliding_window_duration: this.form.slidingWindowDuration || '1h', | ||
run_type: this.form.runType || 'list', | ||
traffic_type: this.form.trafficType || 'split', | ||
// body: this.form.body, | ||
}; | ||
|
@@ -562,7 +640,7 @@ export default Vue.extend({ | |
name: this.form.name, | ||
subject: this.form.subject, | ||
lists: this.form.lists.map((l) => l.id), | ||
messenger: this.form.messenger, | ||
messenger: JSON.stringify(this.selectedMessengers()), | ||
type: 'regular', | ||
tags: this.form.tags, | ||
send_later: this.form.sendLater, | ||
|
@@ -580,6 +658,7 @@ export default Vue.extend({ | |
sliding_window_rate: this.form.slidingWindowRate || 1, | ||
sliding_window_duration: this.form.slidingWindowDuration || '1h', | ||
run_type: this.form.runType || 'list', | ||
traffic_type: this.form.trafficType || 'split', | ||
}; | ||
let typMsg = 'globals.messages.updated'; | ||
|
@@ -694,9 +773,17 @@ export default Vue.extend({ | |
return this.lists.results.filter((l) => this.selListIDs.indexOf(l.id) > -1); | ||
}, | ||
messengers() { | ||
return [...this.serverConfig.messengers]; | ||
return this.serverConfig.messengers.map((item) => { | ||
const row = { | ||
uuid: item.uuid, | ||
name: item.name, | ||
selected: false, | ||
weight: 1, | ||
}; | ||
return row; | ||
}); | ||
}, | ||
}, | ||
|
@@ -747,7 +834,7 @@ export default Vue.extend({ | |
this.$api.getTemplates().then((data) => { | ||
if (data.length > 0) { | ||
if (!this.form.templateId) { | ||
this.form.templateId = data.find((i) => i.isDefault === true).id; | ||
this.form.templateId = data.find((i) => i.isDefault === true)?.id || data[0]?.id; | ||
} | ||
} | ||
}); | ||
|
@@ -759,8 +846,6 @@ export default Vue.extend({ | |
this.activeTab = this.$route.hash.replace('#', ''); | ||
} | ||
}); | ||
} else { | ||
this.form.messenger = 'email'; | ||
} | ||
this.$nextTick(() => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.