|
|
@@ -23,6 +23,7 @@ import * as AsyncLock from 'async-lock'
|
|
|
import { UsersService } from 'src/users/users.service'
|
|
|
import { addHours, addMinutes } from 'date-fns'
|
|
|
import { SysConfig } from 'src/sys-config/entities/sys-config.entity'
|
|
|
+import * as randomstring from 'randomstring'
|
|
|
|
|
|
@Injectable()
|
|
|
export class TaskService implements OnModuleInit {
|
|
|
@@ -537,6 +538,24 @@ export class TaskService implements OnModuleInit {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ refineContent(content: string) {
|
|
|
+ const match = /(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-&?=%.]+/g.exec(content)
|
|
|
+ if (match) {
|
|
|
+ const originUrl = match[0].replace(/\.+$/, '')
|
|
|
+ const http = originUrl.startsWith('http')
|
|
|
+ const url = new URL(http ? originUrl : 'http://' + originUrl)
|
|
|
+ url.searchParams.append('utm_source', 'sms')
|
|
|
+ url.searchParams.append('utm_medium', 'sms')
|
|
|
+ url.searchParams.append('utm_campaign', randomstring.generate(8))
|
|
|
+ let newUrl = url.toString()
|
|
|
+ if (!http) {
|
|
|
+ newUrl = newUrl.replace('http://', '')
|
|
|
+ }
|
|
|
+ return content.replace(originUrl, newUrl)
|
|
|
+ }
|
|
|
+ return content
|
|
|
+ }
|
|
|
+
|
|
|
async dispatchTask(task: Task) {
|
|
|
const batchSize = 200
|
|
|
const taskItems = await this.taskItemRepository.find({
|
|
|
@@ -555,6 +574,9 @@ export class TaskService implements OnModuleInit {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ taskItems.forEach((item) => {
|
|
|
+ item.message = this.refineContent(item.message)
|
|
|
+ })
|
|
|
const taskConfig = {
|
|
|
rcsWait: task.rcsWait || (await this.getConfig('rcs_wait', 2000)),
|
|
|
rcsInterval: task.rcsInterval || (await this.getConfig('rcs_interval', 3000)),
|