WIP
This commit is contained in:
@@ -32,6 +32,7 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
public IEnumerable<string> Commands => COMMANDS;
|
||||
public IEnumerable<DomainType> SupportGroups => GROUPS;
|
||||
public string ReplyTextMessage => null;
|
||||
public string ReplyJsonMessage => null;
|
||||
|
||||
public IEnumerable<ILineMessage> LineMessage
|
||||
{
|
||||
@@ -178,7 +179,7 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
{
|
||||
Action = new UriAction()
|
||||
{
|
||||
Uri = "https://happiness.tours/CellGroup/dinner?openExternalBrowser=1",
|
||||
Uri = $"https://happiness.tours/myapp/dinner/{pastoralDomain.Id}",
|
||||
Label = "我的菜單"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
public IEnumerable<DomainType> SupportGroups => GROUPS;
|
||||
public IEnumerable<ILineMessage> LineMessage => null;
|
||||
|
||||
public string ReplyJsonMessage => null;
|
||||
|
||||
public void Initialize(PastoralDomain pastoralDomain = null)
|
||||
{
|
||||
this.pastoralDomain = pastoralDomain;
|
||||
|
||||
@@ -77,6 +77,7 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
public IEnumerable<string> Commands => COMMANDS;
|
||||
public IEnumerable<DomainType> SupportGroups => GROUPS;
|
||||
public string ReplyTextMessage => null;
|
||||
public string ReplyJsonMessage => null;
|
||||
public IEnumerable<ILineMessage> LineMessage
|
||||
{
|
||||
get
|
||||
@@ -215,7 +216,7 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
{
|
||||
Action = new UriAction()
|
||||
{
|
||||
Uri = "https://happiness.tours/CellGroup/prayer?openExternalBrowser=1",
|
||||
Uri = $"https://happiness.tours/myapp/prayer/{pastoralDomain.Id}",
|
||||
Label = "我的代禱事項"
|
||||
}
|
||||
}
|
||||
@@ -236,6 +237,7 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
}
|
||||
public bool Enabled(PastoralDomain pastoralDomain = null, string command = null)
|
||||
{
|
||||
this.pastoralDomain = pastoralDomain;
|
||||
return COMMANDS.Any(c => c.IndexOf(command) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,13 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
public string ReplyTextMessage => MESSAGES;
|
||||
|
||||
public IEnumerable<ILineMessage> LineMessage => null;
|
||||
public string ReplyJsonMessage => null;
|
||||
|
||||
IEnumerable<DomainType> IAutoReplyCommand.SupportGroups => GROUPS;
|
||||
|
||||
public bool Enabled(PastoralDomain pastoralDomain = null, string command = null)
|
||||
{
|
||||
//this.pastoralDomain = pastoralDomain;
|
||||
return COMMANDS.Any(c => c.IndexOf(command, StringComparison.OrdinalIgnoreCase) == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
public IEnumerable<string> Commands => COMMANDS;
|
||||
public IEnumerable<DomainType> SupportGroups => GROUPS;
|
||||
public string ReplyTextMessage => null;
|
||||
public string ReplyJsonMessage => null;
|
||||
|
||||
public IEnumerable<ILineMessage> LineMessage
|
||||
{
|
||||
@@ -83,7 +84,8 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
Text = $"親愛的 {best.Name},想邀請你來參加這周的幸福聚會唷! 這是這周的邀請函!\n\nhttps://happiness.tours/invitation/{best.Id}",
|
||||
Label = best.Name,
|
||||
//InputOption= "openKeyboard"
|
||||
}
|
||||
},
|
||||
Height = FlexObjectSize.sm,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -28,138 +28,14 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
};
|
||||
private readonly PastoralDomainLogic logic;
|
||||
|
||||
public string Description => "顯示幸福小組分工表 #代表周數";
|
||||
public string Description => "顯示幸福小組分工表 #代表周數 9顯示所有分工";
|
||||
public IEnumerable<string> Commands => COMMANDS;
|
||||
public IEnumerable<DomainType> SupportGroups => GROUPS;
|
||||
public string ReplyTextMessage => null;
|
||||
|
||||
public IEnumerable<ILineMessage> LineMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
List<ILineMessage> list = new List<ILineMessage>();
|
||||
string title = $"W{weekSeq} {week.Topic} 分工表";
|
||||
string imageUrl = $"https://happiness.tours/assets/images/HappinessGroup/week0{weekSeq}.jpg";
|
||||
var flexMessage = new LineFlexMessage();
|
||||
flexMessage.AltText = title;
|
||||
|
||||
#region Header
|
||||
var headerContent = flexMessage.Contents.InitHeader();
|
||||
headerContent.Add(
|
||||
new LineFlexText(title)
|
||||
{
|
||||
Size = FlexObjectSize.lg,
|
||||
Weight = FlexObjectTextWeidht.Bold,
|
||||
Align = "center"
|
||||
});
|
||||
#endregion
|
||||
#region Hero
|
||||
flexMessage.Contents.InitHero()
|
||||
.Add(
|
||||
new LineFlexImage(imageUrl)
|
||||
{
|
||||
Size = FlexObjectSize.full,
|
||||
AspectRatio = "1.5:1"
|
||||
}
|
||||
);
|
||||
#endregion
|
||||
#region Body
|
||||
|
||||
var bodyContent = flexMessage.Contents.InitBody();
|
||||
|
||||
TimeSpan ts = week.Date - DateTime.Now;
|
||||
Console.WriteLine("No. of Minutes (Difference) = {0}", ts.TotalMinutes);
|
||||
bodyContent.Add(
|
||||
new LineFlexText($"再過 {ts.TotalMinutes.ToString("N0")} 分鐘,就是萬眾期待的幸福小組啦!!!")
|
||||
{
|
||||
Size = FlexObjectSize.md,
|
||||
Weight = FlexObjectTextWeidht.Regular,
|
||||
OffsetBottom = FlexObjectSize.xxl,
|
||||
Wrap = true
|
||||
});
|
||||
//bodyContent.Add(
|
||||
// new LineFlexText($"{_event.Time.ToString("MM/dd HH:mm tt")} 準時開飯唷!!")
|
||||
// {
|
||||
// Size = FlexObjectSize.md,
|
||||
// Weight = FlexObjectTextWeidht.Regular,
|
||||
// OffsetBottom = FlexObjectSize.xl,
|
||||
// Wrap = true
|
||||
// });
|
||||
|
||||
bodyContent.Add(
|
||||
new LineFlexText("分工明細")
|
||||
{
|
||||
Size = FlexObjectSize.md,
|
||||
Weight = FlexObjectTextWeidht.Bold,
|
||||
OffsetBottom = FlexObjectSize.md
|
||||
});
|
||||
//$"目前暫無禱告事項唷, 趕快來新增代禱事項吧!!"
|
||||
List<LineFlexBox> comments = new List<LineFlexBox>();
|
||||
|
||||
foreach (var a in week.Tasks)
|
||||
{
|
||||
var name = string.IsNullOrEmpty(a.Tasker)?"N/A": a.Tasker;// logic.GetMemberFirstNameById(a.MemberId);
|
||||
|
||||
var baseLineBox = new LineFlexBox()
|
||||
{
|
||||
Layout = FlexObjectBoxLayout.Baseline,
|
||||
};
|
||||
baseLineBox.Contents.Add(
|
||||
new LineFlexText(a.Type.EnumToDescriptionString())
|
||||
{
|
||||
Size = FlexObjectSize.sm,
|
||||
Color = "#aaaaaa",
|
||||
Flex = 3
|
||||
});
|
||||
baseLineBox.Contents.Add(
|
||||
new LineFlexText(
|
||||
$"{name}"
|
||||
|
||||
)
|
||||
{
|
||||
Size = FlexObjectSize.sm,
|
||||
Color = "#666666",
|
||||
Flex = 3,
|
||||
Wrap = true
|
||||
});
|
||||
baseLineBox.Contents.Add(
|
||||
new LineFlexText(
|
||||
$"內容:{a.Content}"
|
||||
|
||||
)
|
||||
{
|
||||
Size = FlexObjectSize.sm,
|
||||
Color = "#666666",
|
||||
Flex = 7,
|
||||
Wrap = true
|
||||
});
|
||||
bodyContent.Add(baseLineBox);
|
||||
|
||||
}
|
||||
|
||||
bodyContent.Add(new LineFlexSeparator());
|
||||
#endregion
|
||||
#region Footer
|
||||
//flexMessage.Contents.InitFooter()
|
||||
// .Add(
|
||||
// new LineFlexButton()
|
||||
// {
|
||||
// Action = new UriAction()
|
||||
// {
|
||||
// Uri = "https://happiness.tours/CellGroup/dinner?openExternalBrowser=1",
|
||||
// Label = "我的菜單"
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
|
||||
#endregion
|
||||
|
||||
list.Insert(0, flexMessage);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
public string ReplyJsonMessage => jsonMessage;
|
||||
private string jsonMessage;
|
||||
private IEnumerable<ILineMessage> lineMessages;
|
||||
public IEnumerable<ILineMessage> LineMessage => lineMessages;
|
||||
|
||||
public void Initialize(PastoralDomain pastoralDomain = null)
|
||||
{
|
||||
@@ -170,7 +46,7 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
public bool Enabled(PastoralDomain pastoralDomain = null, string command = null)
|
||||
{
|
||||
|
||||
if (pastoralDomain != null && COMMANDS.Any(c => c.IndexOf(command) == 0))
|
||||
if (pastoralDomain != null && command.IndexOf("分工")>-1)
|
||||
{
|
||||
|
||||
this.pastoralDomain = pastoralDomain;
|
||||
@@ -190,10 +66,288 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
week = pastoralDomain.HappinessWeeks.Where(w => w.Date >= DateTime.UtcNow).FirstOrDefault();
|
||||
weekSeq = week.SEQ;
|
||||
}
|
||||
|
||||
if (week != null)
|
||||
{
|
||||
PrepareLineMessage();
|
||||
}
|
||||
else
|
||||
{
|
||||
PrepareAllTaskMessage();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
};
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private void PrepareAllTaskMessage()
|
||||
{
|
||||
this.lineMessages = null;
|
||||
StringBuilder messageContent = new StringBuilder();
|
||||
|
||||
|
||||
messageContent.AppendLine("{ ");
|
||||
messageContent.AppendLine(" \"altText\": \"幸福小組 8 週分工\", ");
|
||||
messageContent.AppendLine(" \"type\": \"flex\", ");
|
||||
messageContent.AppendLine(" \"contents\": { ");
|
||||
messageContent.AppendLine(" \"type\": \"carousel\", ");
|
||||
messageContent.AppendLine(" \"contents\": [ ");
|
||||
|
||||
|
||||
foreach (var week in pastoralDomain.HappinessWeeks.OrderBy(w => w.SEQ))
|
||||
{
|
||||
|
||||
messageContent.AppendLine("{ ");
|
||||
messageContent.AppendLine(" \"type\": \"bubble\", ");
|
||||
messageContent.AppendLine(" \"header\": { ");
|
||||
messageContent.AppendLine(" \"type\": \"box\", ");
|
||||
messageContent.AppendLine(" \"layout\": \"vertical\", ");
|
||||
messageContent.AppendLine(" \"contents\": [ ");
|
||||
messageContent.AppendLine(" { ");
|
||||
messageContent.AppendLine(" \"type\": \"text\", ");
|
||||
messageContent.AppendLine($" \"text\": \"W{week.SEQ} {week.Topic} 分工表\", ");
|
||||
messageContent.AppendLine(" \"flex\": 0, ");
|
||||
messageContent.AppendLine(" \"size\": \"lg\", ");
|
||||
messageContent.AppendLine(" \"weight\": \"bold\", ");
|
||||
messageContent.AppendLine(" \"wrap\": false, ");
|
||||
messageContent.AppendLine(" \"align\": \"center\" ");
|
||||
messageContent.AppendLine(" } ");
|
||||
messageContent.AppendLine(" ], ");
|
||||
messageContent.AppendLine(" \"paddingAll\": \"sm\" ");
|
||||
messageContent.AppendLine(" }, ");
|
||||
messageContent.AppendLine(" \"hero\": { ");
|
||||
messageContent.AppendLine(" \"type\": \"box\", ");
|
||||
messageContent.AppendLine(" \"layout\": \"vertical\", ");
|
||||
messageContent.AppendLine(" \"contents\": [ ");
|
||||
messageContent.AppendLine(" { ");
|
||||
messageContent.AppendLine(" \"type\": \"image\", ");
|
||||
messageContent.AppendLine($" \"url\": \"https://happiness.tours/assets/images/HappinessGroup/week0{week.SEQ}.jpg\", ");
|
||||
messageContent.AppendLine(" \"size\": \"full\", ");
|
||||
messageContent.AppendLine(" \"aspectRatio\": \"1.5:1\" ");
|
||||
messageContent.AppendLine(" } ");
|
||||
messageContent.AppendLine(" ] ");
|
||||
messageContent.AppendLine(" }, ");
|
||||
messageContent.AppendLine(" \"body\": { ");
|
||||
messageContent.AppendLine(" \"type\": \"box\", ");
|
||||
messageContent.AppendLine(" \"layout\": \"vertical\", ");
|
||||
messageContent.AppendLine(" \"contents\": [ ");
|
||||
messageContent.AppendLine(" { ");
|
||||
messageContent.AppendLine(" \"type\": \"text\", ");
|
||||
messageContent.AppendLine(" \"text\": \"分工明細\", ");
|
||||
messageContent.AppendLine(" \"flex\": 0, ");
|
||||
messageContent.AppendLine(" \"size\": \"md\", ");
|
||||
messageContent.AppendLine(" \"offsetBottom\": \"md\", ");
|
||||
messageContent.AppendLine(" \"weight\": \"bold\", ");
|
||||
messageContent.AppendLine(" \"wrap\": false ");
|
||||
messageContent.AppendLine(" }, ");
|
||||
|
||||
foreach (var task in week.Tasks)
|
||||
{
|
||||
messageContent.AppendLine(" { ");
|
||||
messageContent.AppendLine(" \"type\": \"box\", ");
|
||||
messageContent.AppendLine(" \"layout\": \"baseline\", ");
|
||||
messageContent.AppendLine(" \"contents\": [ ");
|
||||
messageContent.AppendLine(" { ");
|
||||
messageContent.AppendLine(" \"type\": \"text\", ");
|
||||
messageContent.AppendLine($" \"text\": \"{task.Type.EnumToDescriptionString()}\", ");
|
||||
messageContent.AppendLine(" \"flex\": 3, ");
|
||||
messageContent.AppendLine(" \"size\": \"sm\", ");
|
||||
messageContent.AppendLine(" \"weight\": \"regular\", ");
|
||||
messageContent.AppendLine(" \"color\": \"#aaaaaa\", ");
|
||||
messageContent.AppendLine(" \"wrap\": false ");
|
||||
messageContent.AppendLine(" }, ");
|
||||
messageContent.AppendLine(" { ");
|
||||
messageContent.AppendLine(" \"type\": \"text\", ");
|
||||
messageContent.AppendLine($" \"text\": \"{task.Tasker} \", ");
|
||||
messageContent.AppendLine(" \"flex\": 3, ");
|
||||
messageContent.AppendLine(" \"size\": \"sm\", ");
|
||||
messageContent.AppendLine(" \"weight\": \"regular\", ");
|
||||
messageContent.AppendLine(" \"color\": \"#666666\", ");
|
||||
messageContent.AppendLine(" \"wrap\": true ");
|
||||
messageContent.AppendLine(" }, ");
|
||||
messageContent.AppendLine(" { ");
|
||||
messageContent.AppendLine(" \"type\": \"text\", ");
|
||||
messageContent.AppendLine($" \"text\": \"內容:{task.Content}\", ");
|
||||
messageContent.AppendLine(" \"flex\": 7, ");
|
||||
messageContent.AppendLine(" \"size\": \"sm\", ");
|
||||
messageContent.AppendLine(" \"weight\": \"regular\", ");
|
||||
messageContent.AppendLine(" \"color\": \"#666666\", ");
|
||||
messageContent.AppendLine(" \"wrap\": true ");
|
||||
messageContent.AppendLine(" } ");
|
||||
messageContent.AppendLine(" ] ");
|
||||
messageContent.AppendLine(" }, ");
|
||||
}
|
||||
|
||||
|
||||
messageContent.AppendLine(" { ");
|
||||
messageContent.AppendLine(" \"type\": \"separator\", ");
|
||||
messageContent.AppendLine(" \"margin\": \"md\" ");
|
||||
messageContent.AppendLine(" } ");
|
||||
messageContent.AppendLine(" ], ");
|
||||
messageContent.AppendLine(" \"paddingBottom\": \"none\" ");
|
||||
messageContent.AppendLine(" }, ");
|
||||
messageContent.AppendLine(" \"footer\": { ");
|
||||
messageContent.AppendLine(" \"type\": \"box\", ");
|
||||
messageContent.AppendLine(" \"layout\": \"vertical\", ");
|
||||
messageContent.AppendLine(" \"contents\": [ ");
|
||||
messageContent.AppendLine(" { ");
|
||||
messageContent.AppendLine(" \"type\": \"button\", ");
|
||||
messageContent.AppendLine(" \"action\": { ");
|
||||
messageContent.AppendLine(" \"type\": \"uri\", ");
|
||||
messageContent.AppendLine(" \"label\": \"管理分工\", ");
|
||||
messageContent.AppendLine($" \"uri\": \"https://happiness.tours/myapp/happinessWeeks/395BBPTU4NG3F?openExternalBrowser={week.SEQ}\" ");
|
||||
messageContent.AppendLine(" }, ");
|
||||
messageContent.AppendLine(" \"style\": \"link\", ");
|
||||
messageContent.AppendLine(" \"height\": \"md\" ");
|
||||
messageContent.AppendLine(" } ");
|
||||
messageContent.AppendLine(" ], ");
|
||||
messageContent.AppendLine(" \"paddingAll\": \"none\" ");
|
||||
messageContent.AppendLine(" } ");
|
||||
if (week.SEQ < 8)
|
||||
{
|
||||
messageContent.AppendLine(" }, ");
|
||||
}
|
||||
else
|
||||
{
|
||||
messageContent.AppendLine(" } ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
messageContent.AppendLine(" ] ");
|
||||
messageContent.AppendLine(" } ");
|
||||
messageContent.AppendLine(" } ");
|
||||
this.jsonMessage = messageContent.ToString();
|
||||
}
|
||||
|
||||
private void PrepareLineMessage()
|
||||
{
|
||||
|
||||
var random = new Random();
|
||||
|
||||
List<ILineMessage> list = new List<ILineMessage>();
|
||||
string title = $"W{weekSeq} {week.Topic} 分工表";
|
||||
string imageUrl = $"https://happiness.tours/assets/images/HappinessGroup/week0{weekSeq}.jpg";
|
||||
var flexMessage = new LineFlexMessage();
|
||||
flexMessage.AltText = title;
|
||||
|
||||
#region Header
|
||||
var headerContent = flexMessage.Contents.InitHeader();
|
||||
headerContent.Add(
|
||||
new LineFlexText(title)
|
||||
{
|
||||
Size = FlexObjectSize.lg,
|
||||
Weight = FlexObjectTextWeidht.Bold,
|
||||
Align = "center"
|
||||
});
|
||||
#endregion
|
||||
#region Hero
|
||||
flexMessage.Contents.InitHero()
|
||||
.Add(
|
||||
new LineFlexImage(imageUrl)
|
||||
{
|
||||
Size = FlexObjectSize.full,
|
||||
AspectRatio = "1.5:1"
|
||||
}
|
||||
);
|
||||
#endregion
|
||||
#region Body
|
||||
|
||||
var bodyContent = flexMessage.Contents.InitBody();
|
||||
|
||||
TimeSpan ts = week.Date - DateTime.Now;
|
||||
Console.WriteLine("No. of Minutes (Difference) = {0}", ts.TotalMinutes);
|
||||
bodyContent.Add(
|
||||
new LineFlexText($"再過 {ts.TotalMinutes.ToString("N0")} 分鐘,就是萬眾期待的幸福小組啦!!!")
|
||||
{
|
||||
Size = FlexObjectSize.md,
|
||||
Weight = FlexObjectTextWeidht.Regular,
|
||||
OffsetBottom = FlexObjectSize.xxl,
|
||||
Wrap = true
|
||||
});
|
||||
//bodyContent.Add(
|
||||
// new LineFlexText($"{_event.Time.ToString("MM/dd HH:mm tt")} 準時開飯唷!!")
|
||||
// {
|
||||
// Size = FlexObjectSize.md,
|
||||
// Weight = FlexObjectTextWeidht.Regular,
|
||||
// OffsetBottom = FlexObjectSize.xl,
|
||||
// Wrap = true
|
||||
// });
|
||||
|
||||
bodyContent.Add(
|
||||
new LineFlexText("分工明細")
|
||||
{
|
||||
Size = FlexObjectSize.md,
|
||||
Weight = FlexObjectTextWeidht.Bold,
|
||||
OffsetBottom = FlexObjectSize.md
|
||||
});
|
||||
//$"目前暫無禱告事項唷, 趕快來新增代禱事項吧!!"
|
||||
List<LineFlexBox> comments = new List<LineFlexBox>();
|
||||
|
||||
foreach (var a in week.Tasks)
|
||||
{
|
||||
var name = string.IsNullOrEmpty(a.Tasker) ? "N/A" : a.Tasker;// logic.GetMemberFirstNameById(a.MemberId);
|
||||
|
||||
var baseLineBox = new LineFlexBox()
|
||||
{
|
||||
Layout = FlexObjectBoxLayout.Baseline,
|
||||
};
|
||||
baseLineBox.Contents.Add(
|
||||
new LineFlexText(a.Type.EnumToDescriptionString())
|
||||
{
|
||||
Size = FlexObjectSize.sm,
|
||||
Color = "#aaaaaa",
|
||||
Flex = 3
|
||||
});
|
||||
baseLineBox.Contents.Add(
|
||||
new LineFlexText(
|
||||
$"{name}"
|
||||
|
||||
)
|
||||
{
|
||||
Size = FlexObjectSize.sm,
|
||||
Color = "#666666",
|
||||
Flex = 3,
|
||||
Wrap = true
|
||||
});
|
||||
baseLineBox.Contents.Add(
|
||||
new LineFlexText(
|
||||
$"內容:{a.Content}"
|
||||
|
||||
)
|
||||
{
|
||||
Size = FlexObjectSize.sm,
|
||||
Color = "#666666",
|
||||
Flex = 7,
|
||||
Wrap = true
|
||||
});
|
||||
bodyContent.Add(baseLineBox);
|
||||
|
||||
}
|
||||
|
||||
bodyContent.Add(new LineFlexSeparator());
|
||||
#endregion
|
||||
#region Footer
|
||||
flexMessage.Contents.InitFooter()
|
||||
.Add(
|
||||
new LineFlexButton()
|
||||
{
|
||||
Action = new UriAction()
|
||||
{
|
||||
Uri = $"https://happiness.tours/myapp/happinessWeeks/{pastoralDomain.Id}",
|
||||
Label = "管理分工"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
#endregion
|
||||
|
||||
list.Insert(0, flexMessage);
|
||||
this.lineMessages = list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace WebAPI.Services.Interfaces
|
||||
string Description { get; }
|
||||
IEnumerable<string> Commands { get; }
|
||||
string ReplyTextMessage { get; }
|
||||
string ReplyJsonMessage { get; }
|
||||
IEnumerable<DomainType> SupportGroups { get; }
|
||||
IEnumerable<ILineMessage> LineMessage { get; }
|
||||
bool Enabled(PastoralDomain pastoralDomain = null, string command = null);
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace WebAPI.Services.Interfaces
|
||||
{
|
||||
public interface IScheduledTask
|
||||
{
|
||||
static DateTime? NextRunningTime { get; set; }
|
||||
string Description { get; }
|
||||
bool CheckTime(DateTime time);
|
||||
Task<bool> RunTask();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.DAL.EFCoreDBF;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Entity.Messenger;
|
||||
using Church.Net.Utility;
|
||||
using LineMessaging;
|
||||
@@ -35,6 +36,7 @@ namespace WebAPI.Services
|
||||
private readonly ILoggingService loggingService;
|
||||
private readonly ICrudLogic<LineMessageClient> clientLogic;
|
||||
private readonly LineMessagingAccountLogic lineMessagingAccountLogic;
|
||||
private readonly ICrudDAL<LineMessagingAccount> lineAccountCrudDAL;
|
||||
private string chatToken;
|
||||
|
||||
private PastoralDomain cellGroup;
|
||||
@@ -43,13 +45,15 @@ namespace WebAPI.Services
|
||||
IEnumerable<IAutoReplyCommand> autoReplyCommands,
|
||||
ILoggingService loggingService,
|
||||
ICrudLogic<LineMessageClient> clientLogic,
|
||||
LineMessagingAccountLogic lineMessagingAccountLogic
|
||||
LineMessagingAccountLogic lineMessagingAccountLogic,
|
||||
ICrudDAL<LineMessagingAccount> lineAccountCrudDAL
|
||||
)
|
||||
{
|
||||
this.autoReplyCommands = autoReplyCommands;
|
||||
this.loggingService = loggingService;
|
||||
this.clientLogic = clientLogic;
|
||||
this.lineMessagingAccountLogic = lineMessagingAccountLogic;
|
||||
this.lineAccountCrudDAL = lineAccountCrudDAL;
|
||||
}
|
||||
public void SendTextMessage(string text, LineGroup target)
|
||||
{
|
||||
@@ -96,6 +100,35 @@ namespace WebAPI.Services
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public async Task<bool> ReplyJsonMessage(string lineId, string jsonMessage)
|
||||
{
|
||||
var test = new LineMessagingClient(this.chatToken);
|
||||
|
||||
//var replyMessage = new LineReplyMessage() { ReplyToken = replyToken };
|
||||
//var messages = new List<ILineMessage>();
|
||||
//foreach (var message in textMessages)
|
||||
//{
|
||||
// messages.Add(new LineTextMessage() { Text = message });
|
||||
//}
|
||||
//replyMessage.Messages = messages;
|
||||
//test.ReplyMessage(replyMessage);
|
||||
|
||||
try
|
||||
{
|
||||
await test.PushJsonMessage(lineId, jsonMessage);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.loggingService.Error(ex, "ReplyTextMessage:75", jsonMessage);
|
||||
|
||||
if (ex.Message == "You have reached your monthly limit.")
|
||||
{
|
||||
this.SendTextMessage("Line Bot Exist Monthly Limit!!!", LineGroup.Chris);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public async Task<bool> ReplyLineMessage(string lineId, IEnumerable<ILineMessage> lineMessages)
|
||||
{
|
||||
var test = new LineMessagingClient(this.chatToken);
|
||||
@@ -212,6 +245,10 @@ namespace WebAPI.Services
|
||||
{
|
||||
await ReplyLineMessage(target, autoReply.LineMessage);
|
||||
}
|
||||
else if (autoReply.ReplyJsonMessage != null)
|
||||
{
|
||||
await ReplyJsonMessage(target, autoReply.ReplyJsonMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyTextMessage(replyToken, autoReply.ReplyTextMessage);
|
||||
@@ -260,7 +297,7 @@ namespace WebAPI.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
cellGroup = group;
|
||||
if (command.IndexOf("#") == 0)
|
||||
{
|
||||
command = command.ToLower().Substring(1);
|
||||
@@ -271,15 +308,18 @@ namespace WebAPI.Services
|
||||
if (autoReply != null)
|
||||
{
|
||||
|
||||
if (autoReply.LineMessage != null)
|
||||
this.chatToken = this.lineAccountCrudDAL.First(x => x.Id == group.LineAccountId)?.ChatToken;
|
||||
if (false == string.IsNullOrEmpty(this.chatToken))
|
||||
{
|
||||
await ReplyLineMessage(cellGroup.LineGroupId, autoReply.LineMessage);
|
||||
if (autoReply.LineMessage != null)
|
||||
{
|
||||
await ReplyLineMessage(cellGroup.LineGroupId, autoReply.LineMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyTextMessage(cellGroup.LineGroupId, autoReply.ReplyTextMessage);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyTextMessage(cellGroup.LineGroupId, autoReply.ReplyTextMessage);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//else if (command == "help" || command == "?")
|
||||
|
||||
@@ -11,7 +11,8 @@ namespace WebAPI.Services.ScheduledTask
|
||||
private readonly LineAutoBotService lineAutoBotService;
|
||||
private readonly ILoggingService loggingService;
|
||||
private readonly PastoralDomainLogic pastoralDomainLogic;
|
||||
private DateTime? nextRunningTime = null;
|
||||
|
||||
public static DateTime? NextRunningTime = null;
|
||||
public MorningPrayer(
|
||||
LineAutoBotService lineAutoBotService,
|
||||
ILoggingService loggingService,
|
||||
@@ -21,19 +22,19 @@ namespace WebAPI.Services.ScheduledTask
|
||||
this.lineAutoBotService = lineAutoBotService;
|
||||
this.loggingService = loggingService;
|
||||
this.pastoralDomainLogic = pastoralDomainLogic;
|
||||
this.SetNextRunningTime();
|
||||
//this.SetNextRunningTime();
|
||||
}
|
||||
public string Description => "Sent out Ark Morning Prayer";
|
||||
|
||||
public bool CheckTime(DateTime time)
|
||||
{
|
||||
if(nextRunningTime == null)
|
||||
if(NextRunningTime == null)
|
||||
{
|
||||
this.SetNextRunningTime();
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return time >= nextRunningTime.Value;
|
||||
return time >= NextRunningTime.Value;
|
||||
}
|
||||
|
||||
public Task<bool> RunTask()
|
||||
@@ -53,8 +54,8 @@ namespace WebAPI.Services.ScheduledTask
|
||||
}
|
||||
private void SetNextRunningTime()
|
||||
{
|
||||
nextRunningTime = DateTimeHelper.Today().AddDays(1).AddHours(8);
|
||||
loggingService.Log($"Scheduled Task {this.Description}", nextRunningTime.Value);
|
||||
NextRunningTime = DateTimeHelper.Today().AddDays(1).AddHours(8);
|
||||
loggingService.Log($"Scheduled Task {this.Description}", NextRunningTime.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user