public async Task StartAsync(CancellationToken cancellationToken) { ILoggerFactory loggerFactory = new LoggerFactory(); var logger = new Logger <WechatyPuppet>(loggerFactory); var PuppetOptions = new Schemas.PuppetOptions() { // eg http://192.168.2.200:8788 Endpoint = Configuration["Wechaty_EndPoint"], Token = Configuration["Wechaty_Token"] }; var grpcPuppet = new GrpcPuppet(PuppetOptions, logger, loggerFactory); var wechatyOptions = new WechatyOptions() { Name = Configuration["Wechaty_Name"], Puppet = grpcPuppet, }; bot = new Wechaty(wechatyOptions, loggerFactory); await bot.OnScan(WechatyScanEventListener) .OnLogin(WechatyLoginEventListener) .OnMessage(WechatyMessageEventListenerAsync) .OnHeartbeat(WechatyHeartbeatEventListener) .Start(); }
public Task Install(Wechaty bot) { bot.OnScan((string qrcode, ScanStatus status, string?data) => { if (status == ScanStatus.Waiting || status == ScanStatus.Timeout) { const string QrcodeServerUrl = "https://wechaty.github.io/qrcode/"; var qrcodeImageUrl = QrcodeServerUrl + qrcode; Console.WriteLine(qrcodeImageUrl); var generator = new Url(qrcode); var payload = generator.ToString(); var qrGenerator = new QRCodeGenerator(); var qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.M); var qrCodeAsi = new AsciiQRCode(qrCodeData); var qrCodeAsAsciiArt = qrCodeAsi.GetGraphic(1); Console.WriteLine(qrCodeAsAsciiArt); } }); return(Task.CompletedTask); }
public Task Install(Wechaty bot) { bot.OnScan((string qrcode, ScanStatus status, string?data) => { const string QrcodeServerUrl = "https://wechaty.github.io/qrcode/"; if (status == ScanStatus.Waiting || status == ScanStatus.Timeout) { var qrcodeImageUrl = QrcodeServerUrl + qrcode; Console.WriteLine(qrcodeImageUrl); } else if (status == ScanStatus.Scanned) { Console.WriteLine(data); } }) .OnLogin((ContactSelf user) => { Console.WriteLine($"{user.Name}在{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}上线了!"); }); return(Task.CompletedTask); }
public async Task StartAsync(CancellationToken cancellationToken) { var PuppetOptions = new Module.Puppet.Schemas.PuppetOptions() { Token = _configuration["WECHATY_PUPPET_HOSTIE_TOKEN"], PuppetService = _configuration["WECHATY_PUPPET"] }; bot = new Wechaty(PuppetOptions); await bot.OnScan(WechatyScanEventListener) .OnLogin(async(ContactSelf user) => { Console.WriteLine($"{user.Name}在{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}上线了!"); }) .OnMessage(WechatyMessageEventListenerAsync) .OnHeartbeat(WechatyHeartbeatEventListener) .OnRoomInvite(WechatyRoomInviteEventListener) .OnRoomJoin(WechatyRoomJoinEventListener) .OnRoomLeave(WechatyRoomLeaveEventListener) .OnRoomTopic(WechatyRoomTopicEventListener) .Start(); }