优化自动回复
This commit is contained in:
1 parent
e80d281017
commit
43587dbdd4
2 files changed
+102
-83
No files matched your search
+15
-17
@@ -46,7 +46,6 @@ namespace TemuKJD.WXForms.TalkForms
|
|||||||
this.line4 = new DevComponents.DotNetBar.Controls.Line();
|
this.line4 = new DevComponents.DotNetBar.Controls.Line();
|
||||||
this.chkIsAutoReply = new System.Windows.Forms.CheckBox();
|
this.chkIsAutoReply = new System.Windows.Forms.CheckBox();
|
||||||
this.splitContainer4 = new System.Windows.Forms.SplitContainer();
|
this.splitContainer4 = new System.Windows.Forms.SplitContainer();
|
||||||
this.progressBarX1 = new DevComponents.DotNetBar.Controls.ProgressBarX();
|
|
||||||
this.dgvShop = new TemuKJD.UserComponent.DataGridViewEx();
|
this.dgvShop = new TemuKJD.UserComponent.DataGridViewEx();
|
||||||
this.colSelect = new TemuKJD.UserComponent.UcDataGridViewCheckBoxColumn(this.components);
|
this.colSelect = new TemuKJD.UserComponent.UcDataGridViewCheckBoxColumn(this.components);
|
||||||
this.colShopLoginName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
this.colShopLoginName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
@@ -103,6 +102,7 @@ namespace TemuKJD.WXForms.TalkForms
|
|||||||
this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
this.dataGridViewLinkColumn2 = new System.Windows.Forms.DataGridViewLinkColumn();
|
this.dataGridViewLinkColumn2 = new System.Windows.Forms.DataGridViewLinkColumn();
|
||||||
|
this.lblAutoReplyStatus = new System.Windows.Forms.Label();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pbLogo)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pbLogo)).BeginInit();
|
||||||
this.panel3.SuspendLayout();
|
this.panel3.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
|
||||||
@@ -136,7 +136,7 @@ namespace TemuKJD.WXForms.TalkForms
|
|||||||
// lblVersionName
|
// lblVersionName
|
||||||
//
|
//
|
||||||
this.lblVersionName.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
this.lblVersionName.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||||
this.lblVersionName.Location = new System.Drawing.Point(31161, 33);
|
this.lblVersionName.Location = new System.Drawing.Point(31695, 33);
|
||||||
//
|
//
|
||||||
// panel3
|
// panel3
|
||||||
//
|
//
|
||||||
@@ -359,7 +359,6 @@ namespace TemuKJD.WXForms.TalkForms
|
|||||||
//
|
//
|
||||||
// splitContainer4.Panel1
|
// splitContainer4.Panel1
|
||||||
//
|
//
|
||||||
this.splitContainer4.Panel1.Controls.Add(this.progressBarX1);
|
|
||||||
this.splitContainer4.Panel1.Controls.Add(this.dgvShop);
|
this.splitContainer4.Panel1.Controls.Add(this.dgvShop);
|
||||||
//
|
//
|
||||||
// splitContainer4.Panel2
|
// splitContainer4.Panel2
|
||||||
@@ -385,19 +384,6 @@ namespace TemuKJD.WXForms.TalkForms
|
|||||||
this.splitContainer4.SplitterDistance = 450;
|
this.splitContainer4.SplitterDistance = 450;
|
||||||
this.splitContainer4.TabIndex = 7;
|
this.splitContainer4.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// progressBarX1
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
this.progressBarX1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
|
|
||||||
this.progressBarX1.Location = new System.Drawing.Point(21, 46);
|
|
||||||
this.progressBarX1.Name = "progressBarX1";
|
|
||||||
this.progressBarX1.Size = new System.Drawing.Size(98, 10);
|
|
||||||
this.progressBarX1.TabIndex = 224;
|
|
||||||
this.progressBarX1.Text = "下载中";
|
|
||||||
this.progressBarX1.Visible = false;
|
|
||||||
//
|
|
||||||
// dgvShop
|
// dgvShop
|
||||||
//
|
//
|
||||||
this.dgvShop.AllowUserToAddRows = false;
|
this.dgvShop.AllowUserToAddRows = false;
|
||||||
@@ -965,6 +951,7 @@ namespace TemuKJD.WXForms.TalkForms
|
|||||||
//
|
//
|
||||||
// pnlTalk
|
// pnlTalk
|
||||||
//
|
//
|
||||||
|
this.pnlTalk.Controls.Add(this.lblAutoReplyStatus);
|
||||||
this.pnlTalk.Controls.Add(this.chkShowAutoReplyNum);
|
this.pnlTalk.Controls.Add(this.chkShowAutoReplyNum);
|
||||||
this.pnlTalk.Controls.Add(this.chkShowShopStatistics);
|
this.pnlTalk.Controls.Add(this.chkShowShopStatistics);
|
||||||
this.pnlTalk.Controls.Add(this.chkIsAutoReLogin);
|
this.pnlTalk.Controls.Add(this.chkIsAutoReLogin);
|
||||||
@@ -1125,6 +1112,17 @@ namespace TemuKJD.WXForms.TalkForms
|
|||||||
this.dataGridViewLinkColumn2.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
|
this.dataGridViewLinkColumn2.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
|
||||||
this.dataGridViewLinkColumn2.Width = 106;
|
this.dataGridViewLinkColumn2.Width = 106;
|
||||||
//
|
//
|
||||||
|
// label5
|
||||||
|
//
|
||||||
|
this.lblAutoReplyStatus.AutoSize = true;
|
||||||
|
this.lblAutoReplyStatus.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||||
|
this.lblAutoReplyStatus.Location = new System.Drawing.Point(0, 527);
|
||||||
|
this.lblAutoReplyStatus.Name = "label5";
|
||||||
|
this.lblAutoReplyStatus.Size = new System.Drawing.Size(43, 17);
|
||||||
|
this.lblAutoReplyStatus.TabIndex = 207;
|
||||||
|
this.lblAutoReplyStatus.Text = "label5";
|
||||||
|
this.lblAutoReplyStatus.Visible = false;
|
||||||
|
//
|
||||||
// WxTalkForm
|
// WxTalkForm
|
||||||
//
|
//
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||||
@@ -1241,8 +1239,8 @@ namespace TemuKJD.WXForms.TalkForms
|
|||||||
private System.Windows.Forms.DataGridViewCheckBoxColumn colCanUse;
|
private System.Windows.Forms.DataGridViewCheckBoxColumn colCanUse;
|
||||||
private DevComponents.DotNetBar.PanelEx btnMultiLogin;
|
private DevComponents.DotNetBar.PanelEx btnMultiLogin;
|
||||||
private DevComponents.DotNetBar.PanelEx btnChangeAddress;
|
private DevComponents.DotNetBar.PanelEx btnChangeAddress;
|
||||||
private DevComponents.DotNetBar.Controls.ProgressBarX progressBarX1;
|
|
||||||
private System.Windows.Forms.Label lblProgress;
|
private System.Windows.Forms.Label lblProgress;
|
||||||
private System.Windows.Forms.TabPage tabPage3;
|
private System.Windows.Forms.TabPage tabPage3;
|
||||||
|
private System.Windows.Forms.Label lblAutoReplyStatus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,16 +242,29 @@ namespace TemuKJD.WXForms.TalkForms
|
|||||||
|
|
||||||
if (chkIsAutoReply.Checked && 1==1)
|
if (chkIsAutoReply.Checked && 1==1)
|
||||||
{
|
{
|
||||||
while (lstAutoReplayParam.Count > 0)
|
Invoke(new Action(() => { lblAutoReplyStatus.Visible = true; lblAutoReplyStatus.Text = "自动回复中... " + DateTime.Now.ToString("HH:mm:ss"); }));
|
||||||
{
|
|
||||||
AutoReplayParam autoReplayParam = lstAutoReplayParam.FirstOrDefault();
|
|
||||||
var autoReplayParamLst = lstAutoReplayParam.Where(r => r.nickName == autoReplayParam.nickName).ToList();
|
|
||||||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == autoReplayParam.shopId);
|
|
||||||
if (shop == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// 选择正确的用户
|
if (lstAutoReplayParam.Count > 0)
|
||||||
var jsStr1 = @"function clickUser() {
|
{
|
||||||
|
var tmpAutoReplayParamLst = new List<AutoReplayParam>();
|
||||||
|
foreach (var rp in lstAutoReplayParam)
|
||||||
|
{
|
||||||
|
if (!tmpAutoReplayParamLst.Any(r => r.nickName == rp.nickName))
|
||||||
|
tmpAutoReplayParamLst.Add(rp);
|
||||||
|
}
|
||||||
|
foreach (AutoReplayParam autoReplayParam in tmpAutoReplayParamLst)
|
||||||
|
{
|
||||||
|
//AutoReplayParam autoReplayParam = lstAutoReplayParam.FirstOrDefault();
|
||||||
|
var autoReplayParamLst = lstAutoReplayParam.Where(r => r.nickName == autoReplayParam.nickName).ToList();
|
||||||
|
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == autoReplayParam.shopId);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
lstAutoReplayParam.RemoveAll(r => r.shopId == autoReplayParam.shopId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选择正确的用户
|
||||||
|
var jsStr1 = @"function clickUser() {
|
||||||
var users = document.getElementsByClassName('user-nickname');
|
var users = document.getElementsByClassName('user-nickname');
|
||||||
for (i=0; i<users.length; i++) {
|
for (i=0; i<users.length; i++) {
|
||||||
if (users[i].innerHTML == '" + autoReplayParam.nickName + @"') {
|
if (users[i].innerHTML == '" + autoReplayParam.nickName + @"') {
|
||||||
@@ -263,12 +276,13 @@ namespace TemuKJD.WXForms.TalkForms
|
|||||||
return 'fail';
|
return 'fail';
|
||||||
}
|
}
|
||||||
clickUser();";
|
clickUser();";
|
||||||
var response1 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1);
|
var response1 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1);
|
||||||
response1.Wait(2000);
|
response1.Wait(2000);
|
||||||
if (response1.Result.Result.ParseToString() != "success")
|
if (response1.Result.Result.ParseToString() != "success")
|
||||||
{
|
{
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(Randomx.GetId(500, 1000));
|
||||||
jsStr1 = @"function clickUser() {
|
Invoke(new Action(() => { lblAutoReplyStatus.Text = "当前用户获取失败,尝试获取全部用户 " + DateTime.Now.ToString("HH:mm:ss"); }));
|
||||||
|
var jsStr2 = @"function clickAllUser() {
|
||||||
var users = document.getElementsByClassName('tab-list-item');
|
var users = document.getElementsByClassName('tab-list-item');
|
||||||
for (i=0; i<users.length; i++) {
|
for (i=0; i<users.length; i++) {
|
||||||
if (users[i].innerHTML == '全部' && users[i].parentElement.innerHTML.indexOf('当前会话') !== -1) {
|
if (users[i].innerHTML == '全部' && users[i].parentElement.innerHTML.indexOf('当前会话') !== -1) {
|
||||||
@@ -276,72 +290,79 @@ namespace TemuKJD.WXForms.TalkForms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clickUser();";
|
clickAllUser();";
|
||||||
|
var response2 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr2);
|
||||||
|
response2.Wait(2000);
|
||||||
|
Thread.Sleep(Randomx.GetId(500, 1000));
|
||||||
|
|
||||||
|
response1 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1);
|
||||||
|
response1.Wait(2000);
|
||||||
|
}
|
||||||
|
Thread.Sleep(Randomx.GetId(1500, 2000));
|
||||||
|
|
||||||
|
// 输入内容
|
||||||
|
// 默认回复
|
||||||
|
string replyContent = "亲,客服打包去了,请稍候!";
|
||||||
|
// 分割完整语句匹配
|
||||||
|
var replyContentLst = LstTalkTemplatePair
|
||||||
|
.Where(t => lstAutoReplayParam.Any(a => t.Key.Split('|').Any(k => !k.IsNullOrEmpty() && a.talkContent == k)))
|
||||||
|
.OrderBy(x => Randomx.GetId(100000)).ToList();
|
||||||
|
// 分割完整语句匹配(过滤标点符号)
|
||||||
|
if (replyContentLst.Count == 0)
|
||||||
|
replyContentLst = LstTalkTemplatePair
|
||||||
|
.Where(t => lstAutoReplayParam.Any(a => t.Key.Split('|').Any(k => !k.IsNullOrEmpty() && a.talkContent.Trim('?', '?', ',', ',', '.', '。', '!', '!') == k)))
|
||||||
|
.OrderBy(x => Randomx.GetId(100000)).ToList();
|
||||||
|
// 反向包含匹配
|
||||||
|
if (replyContentLst.Count == 0)
|
||||||
|
replyContentLst = LstTalkTemplatePair.Where(t => lstAutoReplayParam.Any(a => a.talkContent.Contains(t.Key))).OrderBy(x => Randomx.GetId(100000)).ToList();
|
||||||
|
|
||||||
|
// 不能匹配的发默认消息
|
||||||
|
if (replyContentLst.Count == 0)
|
||||||
|
replyContentLst = LstTalkTemplatePair.Where(t => t.Key.IsNullOrEmpty()).OrderBy(x => Randomx.GetId(100000)).ToList();
|
||||||
|
if (replyContentLst.Count > 0)
|
||||||
|
replyContent = replyContentLst.FirstOrDefault().Value;
|
||||||
|
shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(KJDForms.ShopForms.ShopLoginForm.sInputValueChange2);
|
||||||
|
jsStr1 = "var txtarea = document.getElementById('input-textarea'); " +
|
||||||
|
"changeReactInputValue(txtarea,'" + replyContent + "');";
|
||||||
response1 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1);
|
response1 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1);
|
||||||
response1.Wait(2000);
|
response1.Wait(2000);
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(Randomx.GetId(100, 200));
|
||||||
|
|
||||||
continue;
|
// 点击回车发送自动回复
|
||||||
}
|
jsStr1 = @"var event = new KeyboardEvent('keydown', {
|
||||||
Thread.Sleep(1500);
|
|
||||||
|
|
||||||
// 输入内容
|
|
||||||
// 默认回复
|
|
||||||
string replyContent = "亲,客服打包去了,请稍候!";
|
|
||||||
// 分割完整语句匹配
|
|
||||||
var replyContentLst = LstTalkTemplatePair
|
|
||||||
.Where(t => lstAutoReplayParam.Any(a => t.Key.Split('|').Any(k => !k.IsNullOrEmpty() && a.talkContent == k)))
|
|
||||||
.OrderBy(x => Randomx.GetId(100000)).ToList();
|
|
||||||
// 分割完整语句匹配(过滤标点符号)
|
|
||||||
if (replyContentLst.Count == 0)
|
|
||||||
replyContentLst = LstTalkTemplatePair
|
|
||||||
.Where(t => lstAutoReplayParam.Any(a => t.Key.Split('|').Any(k => !k.IsNullOrEmpty() && a.talkContent.Trim('?', '?', ',', ',', '.', '。', '!', '!') == k)))
|
|
||||||
.OrderBy(x => Randomx.GetId(100000)).ToList();
|
|
||||||
// 反向包含匹配
|
|
||||||
if (replyContentLst.Count == 0)
|
|
||||||
replyContentLst = LstTalkTemplatePair.Where(t => lstAutoReplayParam.Any(a => a.talkContent.Contains(t.Key))).OrderBy(x => Randomx.GetId(100000)).ToList();
|
|
||||||
|
|
||||||
// 不能匹配的发默认消息
|
|
||||||
if (replyContentLst.Count == 0)
|
|
||||||
replyContentLst = LstTalkTemplatePair.Where(t => t.Key.IsNullOrEmpty()).OrderBy(x => Randomx.GetId(100000)).ToList();
|
|
||||||
if (replyContentLst.Count > 0)
|
|
||||||
replyContent = replyContentLst.FirstOrDefault().Value;
|
|
||||||
shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(KJDForms.ShopForms.ShopLoginForm.sInputValueChange2);
|
|
||||||
jsStr1 = "var txtarea = document.getElementById('input-textarea'); " +
|
|
||||||
"changeReactInputValue(txtarea,'" + replyContent + "');";
|
|
||||||
response1 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1);
|
|
||||||
response1.Wait(2000);
|
|
||||||
Thread.Sleep(Randomx.GetId(100, 200));
|
|
||||||
|
|
||||||
// 点击回车发送自动回复
|
|
||||||
jsStr1 = @"var event = new KeyboardEvent('keydown', {
|
|
||||||
key: 'Enter',
|
key: 'Enter',
|
||||||
keyCode: 13,
|
keyCode: 13,
|
||||||
code: 'Enter',
|
code: 'Enter',
|
||||||
which: 13
|
which: 13
|
||||||
});
|
});
|
||||||
txtarea.dispatchEvent(event);";
|
txtarea.dispatchEvent(event);";
|
||||||
response1 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1);
|
response1 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1);
|
||||||
response1.Wait(2000);
|
response1.Wait(2000);
|
||||||
|
|
||||||
// 删除队列里的消息
|
// 删除队列里的消息
|
||||||
lstAutoReplayParam.RemoveAll(r => r.nickName == autoReplayParam.nickName);
|
lstAutoReplayParam.RemoveAll(r => r.nickName == autoReplayParam.nickName);
|
||||||
|
|
||||||
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(x => x.Cells["colShopId"].Value.ToString() == shop.ShopId);
|
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(x => x.Cells["colShopId"].Value.ToString() == shop.ShopId);
|
||||||
if (row != null)
|
if (row != null)
|
||||||
{
|
|
||||||
int AutoReplyCount = dicTalkAutoReplyCount.FirstOrDefault(t => t.Key == shop.ShopId).Value.ParseToInt();
|
|
||||||
AutoReplyCount++;
|
|
||||||
dicTalkAutoReplyCount[shop.ShopId] = AutoReplyCount;
|
|
||||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_talk_auto_reply_count", dicTalkAutoReplyCount);
|
|
||||||
Invoke(new Action(() =>
|
|
||||||
{
|
{
|
||||||
row.Cells["colAutoReplyCount"].Value = AutoReplyCount;
|
int AutoReplyCount = dicTalkAutoReplyCount.FirstOrDefault(t => t.Key == shop.ShopId).Value.ParseToInt();
|
||||||
}));
|
AutoReplyCount++;
|
||||||
|
dicTalkAutoReplyCount[shop.ShopId] = AutoReplyCount;
|
||||||
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_talk_auto_reply_count", dicTalkAutoReplyCount);
|
||||||
|
Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
row.Cells["colAutoReplyCount"].Value = AutoReplyCount;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
Invoke(new Action(() => { lblAutoReplyStatus.Text = autoReplayParam.shopId + " 已尝试发送自动回复 " + DateTime.Now.ToString("HH:mm:ss"); }));
|
||||||
|
Thread.Sleep(Randomx.GetId(500, 600));
|
||||||
}
|
}
|
||||||
Thread.Sleep(Randomx.GetId(100, 200));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Invoke(new Action(() => { lblAutoReplyStatus.Visible = false; }));
|
||||||
|
}
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user