public Task Install(Wechaty bot) { bot.OnMessage(async(Message message) => { if (message.Type == MessageType.Text) { if (_config.Ding == message.Text) { await message.Say(_config.Dong); } } }); return(Task.CompletedTask); }
public Task Install(Wechaty bot) { _ = bot.OnMessage((message) => { if (message.Text == "ding") { message.Say("dong"); } if (message.Text == "dong") { message.Say("ding"); } }); return(Task.CompletedTask); }
public async Task StartAsync(CancellationToken cancellationToken) { var PuppetOptions = new Module.Puppet.Schemas.PuppetOptions() { Token = _configuration["WECHATY_PUPPET_SERVICE_TOKEN"], }; bot = new Wechaty(PuppetOptions); // Automatic plug-in registration //var serviceCollection = new ServiceCollection() // .AddSingleton<IWechatPlugin, ScanPlugin>() // .AddSingleton<IWechatPlugin, DingDongPlugin>(); //var plugins = serviceCollection.BuildServiceProvider().GetServices<IWechatPlugin>().ToArray(); // Manual plug-in registration var qrCodeTerminalPlugin = new QRCodeTerminalPlugin(); var dingDongPlugin = new DingDongPlugin(); bot.Use(qrCodeTerminalPlugin) .Use(dingDongPlugin); 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(); }