Skip to content

Commit 1e871b5

Browse files
committed
Add .net/.netcore implement chatbot
0 parents  commit 1e871b5

21 files changed

+11729
-0
lines changed

.gitattributes

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

.gitignore

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# ---> C Sharp
2+
.vs/
3+
.idea/
4+
.DS_Store
5+
*.zip
6+
*.rar
7+
*.dat
8+
*.cfg
9+
*.user
10+
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
11+
[Bb]in/
12+
[Oo]bj/
13+
14+
# mstest test results
15+
TestResults
16+
17+
## Ignore Visual Studio temporary files, build results, and
18+
## files generated by popular Visual Studio add-ons.
19+
20+
# User-specific files
21+
*.suo
22+
*.user
23+
*.sln.docstates
24+
25+
# Build results
26+
[Dd]ebug/
27+
[Rr]elease/
28+
x64/
29+
*_i.c
30+
*_p.c
31+
*.ilk
32+
*.meta
33+
*.obj
34+
*.pch
35+
*.pdb
36+
*.pgc
37+
*.pgd
38+
*.rsp
39+
*.sbr
40+
*.tlb
41+
*.tli
42+
*.tlh
43+
*.tmp
44+
*.log
45+
*.vspscc
46+
*.vssscc
47+
.builds
48+
49+
# Visual C++ cache files
50+
ipch/
51+
*.aps
52+
*.ncb
53+
*.opensdf
54+
*.sdf
55+
56+
# Visual Studio profiler
57+
*.psess
58+
*.vsp
59+
*.vspx
60+
61+
# Guidance Automation Toolkit
62+
*.gpState
63+
64+
# ReSharper is a .NET coding add-in
65+
_ReSharper*
66+
67+
# NCrunch
68+
*.ncrunch*
69+
.*crunch*.local.xml
70+
71+
# Installshield output folder
72+
[Ee]xpress
73+
74+
# DocProject is a documentation generator add-in
75+
DocProject/buildhelp/
76+
DocProject/Help/*.HxT
77+
DocProject/Help/*.HxC
78+
DocProject/Help/*.hhc
79+
DocProject/Help/*.hhk
80+
DocProject/Help/*.hhp
81+
DocProject/Help/Html2
82+
DocProject/Help/html
83+
84+
# Click-Once directory
85+
publish
86+
87+
# Publish Web Output
88+
*.Publish.xml
89+
90+
# NuGet Packages Directory
91+
packages
92+
93+
# Windows Azure Build Output
94+
csx
95+
*.build.csdef
96+
97+
# Windows Store app package directory
98+
AppPackages/
99+
100+
# Others
101+
[Bb]in
102+
[Oo]bj
103+
sql
104+
TestResults
105+
[Tt]est[Rr]esult*
106+
*.Cache
107+
ClientBin
108+
[Ss]tyle[Cc]op.*
109+
~$*
110+
*.dbmdl
111+
Generated_Code #added for RIA/Silverlight projects
112+
113+
# Backup & report files from converting an old project file to a newer
114+
# Visual Studio version. Backup files are not needed, because we have git ;-)
115+
_UpgradeReport_Files/
116+
Backup*/
117+
UpgradeLog*.XML
118+

ChatBot.sln

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28010.2026
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tinode.ChatBot.DemoNet46", "Tinode.ChatBot.DemoNet46\Tinode.ChatBot.DemoNet46.csproj", "{B40386E3-EE17-4709-B6FD-0202C8B6983B}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tinode.ChatBot", "Tinode.ChatBot\Tinode.ChatBot.csproj", "{7ED0D9CF-EF11-4BE2-A7CA-AD8395F2A254}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tinode.ChatBot.DemoNetCore", "Tinode.ChatBot.DemoNetCore\Tinode.ChatBot.DemoNetCore.csproj", "{C4CA23ED-33AA-4B91-A6D2-C5C3C30D76B7}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{B40386E3-EE17-4709-B6FD-0202C8B6983B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{B40386E3-EE17-4709-B6FD-0202C8B6983B}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{B40386E3-EE17-4709-B6FD-0202C8B6983B}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{B40386E3-EE17-4709-B6FD-0202C8B6983B}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{7ED0D9CF-EF11-4BE2-A7CA-AD8395F2A254}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{7ED0D9CF-EF11-4BE2-A7CA-AD8395F2A254}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{7ED0D9CF-EF11-4BE2-A7CA-AD8395F2A254}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{7ED0D9CF-EF11-4BE2-A7CA-AD8395F2A254}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{C4CA23ED-33AA-4B91-A6D2-C5C3C30D76B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{C4CA23ED-33AA-4B91-A6D2-C5C3C30D76B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{C4CA23ED-33AA-4B91-A6D2-C5C3C30D76B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{C4CA23ED-33AA-4B91-A6D2-C5C3C30D76B7}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {5F6495E4-8961-4CE7-A296-89A69C6EF600}
36+
EndGlobalSection
37+
EndGlobal

Tinode.ChatBot.DemoNet46/App.config

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="System.Interactive.Async" publicKeyToken="94bc3704cddfc263" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
14+
</configuration>

Tinode.ChatBot.DemoNet46/Program.cs

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using CommandLine;
2+
using Google.Protobuf;
3+
using Pbx;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
using Tinode.ChatBot;
11+
12+
namespace Tinode.ChatBot.DemoNet46
13+
{
14+
class Program
15+
{
16+
public class CmdOptions
17+
{
18+
[Option('C', "login-cookie", Required = false, Default = ".tn-cookie", HelpText = "read credentials from the provided cookie file")]
19+
public string CookieFile { get; set; }
20+
[Option('T', "login-token", Required = false, HelpText = "login using token authentication")]
21+
public string Token { get; set; }
22+
[Option('B', "login-basic", Required = false, HelpText = "login using basic authentication username:password")]
23+
public string Basic { get; set; }
24+
[Option('L', "listen", Required = false, Default = "0.0.0.0:40052", HelpText = "address to listen on for incoming Plugin API calls")]
25+
public string Listen { get; set; }
26+
[Option('S', "server", Required = false, Default = "localhost:6061", HelpText = "address of Tinode server gRPC endpoint")]
27+
public string Host { get; set; }
28+
}
29+
30+
/// <summary>
31+
/// ChatBot auto reply implement
32+
/// </summary>
33+
public class BotReponse : IBotResponse
34+
{
35+
public string ThinkAndReply(ServerData message)
36+
{
37+
return DateTime.Now.ToLongDateString();
38+
}
39+
40+
}
41+
42+
static ChatBot bot;
43+
static void Main(string[] args)
44+
{
45+
Console.CancelKeyPress += Console_CancelKeyPress;
46+
string schemaArg = string.Empty;
47+
string secretArg = string.Empty;
48+
string cookieFile = string.Empty;
49+
string host = string.Empty;
50+
string listen = string.Empty;
51+
Parser.Default.ParseArguments<CmdOptions>(args)
52+
.WithParsed<CmdOptions>(o =>
53+
{
54+
if (!string.IsNullOrEmpty(o.Host))
55+
{
56+
host = o.Host;
57+
Console.WriteLine($"gRPC server:{host}");
58+
}
59+
if (!string.IsNullOrEmpty(o.Listen))
60+
{
61+
listen = o.Listen;
62+
Console.WriteLine($"Plugin API calls Listen server:{listen}");
63+
}
64+
if (!string.IsNullOrEmpty(o.Token))
65+
{
66+
schemaArg = "token";
67+
secretArg = Encoding.ASCII.GetString(Encoding.Default.GetBytes(o.Token));
68+
Console.WriteLine($"Login in with token {o.Token}");
69+
bot = new ChatBot(serverHost: host, listen: listen, schema: schemaArg, secret: secretArg);
70+
}
71+
else if (!string.IsNullOrEmpty(o.Basic))
72+
{
73+
schemaArg = "basic";
74+
secretArg = Encoding.UTF8.GetString(Encoding.Default.GetBytes(o.Basic));
75+
Console.WriteLine($"Login in with login:password {o.Basic}");
76+
bot = new ChatBot(serverHost: host, listen: listen, schema: schemaArg, secret: secretArg);
77+
}
78+
else
79+
{
80+
cookieFile = o.CookieFile;
81+
Console.WriteLine($"Login in with cookie file {o.CookieFile}");
82+
bot = new ChatBot(serverHost: host, listen: listen, cookie: cookieFile, schema: string.Empty, secret: string.Empty);
83+
if (bot.ReadAuthCookie(out var schem, out var secret))
84+
{
85+
bot.Schema = schem;
86+
bot.Secret = secret;
87+
}
88+
else
89+
{
90+
Console.WriteLine("Login in with cookie file failed, please check your credentials and try again... Press any key to exit.");
91+
Console.ReadKey();
92+
return;
93+
}
94+
}
95+
bot.BotResponse = new BotReponse();
96+
bot.Start().Wait();
97+
98+
Console.WriteLine("[Bye Bye] ChatBot Stopped");
99+
});
100+
101+
}
102+
103+
private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
104+
{
105+
bot.Stop();
106+
}
107+
}
108+
109+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// 有关程序集的一般信息由以下
6+
// 控制。更改这些特性值可修改
7+
// 与程序集关联的信息。
8+
[assembly: AssemblyTitle("Tinode.ChatBot.DemoNet46")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Tinode.ChatBot.DemoNet46")]
13+
[assembly: AssemblyCopyright("https://github.com/tinode/chat")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// 将 ComVisible 设置为 false 会使此程序集中的类型
18+
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19+
//请将此类型的 ComVisible 特性设置为 true。
20+
[assembly: ComVisible(false)]
21+
22+
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23+
[assembly: Guid("b40386e3-ee17-4709-b6fd-0202c8b6983b")]
24+
25+
// 程序集的版本信息由下列四个值组成:
26+
//
27+
// 主版本
28+
// 次版本
29+
// 生成号
30+
// 修订号
31+
//
32+
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
33+
// 方法是按如下所示使用“*”: :
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)