示例#1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="youtubeClient"></param>
 /// <param name="searchOptions"></param>
 /// <param name="slackClient"></param>
 /// <param name="log"></param>
 public Watcher(Slack.Client slackClient, Youtube.Client youtubeClient, IOptions <Youtube.SearchOptions> searchOptions, TraceWriter log)
 {
     _slackClient   = slackClient ?? throw new ArgumentNullException(nameof(slackClient));
     _youtubeClient = youtubeClient ?? throw new ArgumentNullException(nameof(youtubeClient));
     _searchOptions = searchOptions ?? throw new ArgumentNullException(nameof(searchOptions));
     _log           = log ?? throw new ArgumentNullException(nameof(log));
 }
示例#2
0
 public MessageEventArgs(Slack.Client Client, dynamic Data)
 {
     _client  = Client;
     _channel = Data.channel;
     _user    = Data.user;
     _text    = Data.text;
     _ts      = new Slack.TimeStamp((String)Data.ts);
     _team    = Data.team;
 }
示例#3
0
 public Text(Slack.Client Client, dynamic Data)
 {
     _client = Client;
     _type   = Utility.TryGetProperty(Data, "type");
     _ts     = new Slack.TimeStamp(Utility.TryGetProperty(Data, "ts", 0));
     _user   = Utility.TryGetProperty(Data, "user");
     if (_user == "")
     {
         _user = Utility.TryGetProperty(Data, "username");
     }
     _text = Utility.TryGetProperty(Data, "text");
 }
 public MessageEditEventArgs(Slack.Client Client, dynamic Data)
 {
     _client   = Client;
     _channel  = Data.channel;
     _event_ts = Data.event_ts;
     _hidden   = Data.hidden;
     if (Utility.HasProperty(Data, "message"))
     {
         _message = new Messages.Message(Data.message);
     }
     _previous_message = new Previous_Message(Data.previous_message);
     _subtype          = Data.subtype;
     _ts = new Slack.TimeStamp((String)Data.ts);
 }
            public ListResponse(Slack.Client client, dynamic Response)
            {
                ims = new List <IM>();
                if (!Utility.HasProperty(Response, "ims"))
                {
                    return;
                }
                IM objIM;

                foreach (dynamic im in Response.ims)
                {
                    objIM                 = new IM(client);
                    objIM.id              = Utility.TryGetProperty(im, "id");
                    objIM.is_im           = Utility.TryGetProperty(im, "is_im", false);
                    objIM.user            = Utility.TryGetProperty(im, "user");
                    objIM.created         = new TimeStamp(Utility.TryGetProperty(im, "created"));
                    objIM.is_user_deleted = Utility.TryGetProperty(im, "is_user_deleted", false);
                    ims.Add(objIM);
                }
            }
        //main entry point for application
        static void Main(string[] args)
        {
            //this app works by accepting a single parameter which is the slack API key
            if (args.Length == 0)
            {
                Console.WriteLine("You must pass your api token as the first command line parameter");
                return;
            }

            //this is used below to integrate slack with time tracker service
            TimeTracker_LoadAccounts();

            //create a new slack client
            client = new Slack.Client(args[0]);

            //subscribe to any of the events that may interest you
            client.ServiceConnected        += new Slack.Client.ServiceConnectedEventHandler(client_ServiceConnected);
            client.ServiceConnectionFailed += new Slack.Client.ServiceConnectionFailedEventHandler(client_ServiceDisconnected_ServiceConnectionFailure);
            client.ServiceDisconnected     += new Slack.Client.ServiceDisconnectedEventHandler(client_ServiceDisconnected_ServiceConnectionFailure);

            client.Hello                   += new Slack.Client.HelloEventHandler(client_Hello);
            client.DataReceived            += new Slack.Client.DataReceivedEventHandler(client_DataReceived);
            client.PresenceChanged         += new Slack.Client.PresenceChangedEventHandler(client_PresenceChanged);
            client.UserTyping              += new Slack.Client.UserTypingEventHandler(client_UserTyping);
            client.Message                 += new Slack.Client.MessageEventHandler(client_Message);
            client.MesssageEdit            += new Slack.Client.MessageEditEventHandler(client_MessageEdit);
            client.DoNotDisturbUpdatedUser += new Slack.Client.DoNotDistrubUpdatedUserEventHandler(client_DoNotDisturbUpdatedUser);


            //connect to the slack service
            client.Connect();

            //simply hold application open until user presses enter
            Console.WriteLine("Press Enter to Terminate.");
            Console.ReadLine();

            //disconnect from slack service
            shutdown = true;
            client.Disconnect();
        }
        public static void Run([TimerTrigger("0 0 * * * *")] TimerInfo myTimer, TraceWriter log)
        {
            try
            {
                // read options
                var slackOptions = new Slack.Options
                {
                    WebhookUrl = ConfigurationManager.AppSettings["Slack:WebhookUrl"]
                };
                var youTubeOptions = new Youtube.Options
                {
                    ApiKey          = ConfigurationManager.AppSettings["YouTube:ApiKey"],
                    ApplicationName = ConfigurationManager.AppSettings["YouTube:ApplicationName"]
                };
                var searchOptions = new Youtube.SearchOptions
                {
                    Options = JsonConvert.DeserializeObject <List <Youtube.Option> >(ConfigurationManager.AppSettings["SearchOptions"])
                };

                // get last run date
                var lastRunDate = myTimer.ScheduleStatus.Last.ToUniversalTime();
                log.Info($"lastRunDate: {lastRunDate:F}");

                // create clients
                var youtubeClient = new Youtube.Client(new Microsoft.Extensions.Options.OptionsWrapper <Youtube.Options>(youTubeOptions));
                var slackClient   = new Slack.Client(new Microsoft.Extensions.Options.OptionsWrapper <Slack.Options>(slackOptions));

                // run
                var watcher = new Watcher(slackClient, youtubeClient, new Microsoft.Extensions.Options.OptionsWrapper <Youtube.SearchOptions>(searchOptions), log);
                watcher.Process(lastRunDate);

                var response = slackClient.PostAsync(new Slack.Message {
                    Text = $"Social Search Executed with published after {lastRunDate}"
                }).Result;
            }
            catch (Exception e)
            {
                log.Error($"Exception {e.Message}");
            }
        }
示例#8
0
        public HistoryResponse(Slack.Client Client, Slack.Channels.HistoryRequestArgs args, dynamic Response)
        {
            _client   = Client;
            _args     = args;
            _latest   = new Slack.TimeStamp(Utility.TryGetProperty(Response, "latest", 0).ToString());
            _hasMore  = Utility.TryGetProperty(Response, "has_more", false);
            _messages = new List <Messages.IMessage>();
            String strType;

            foreach (dynamic message in Response.messages)
            {
                strType = message.type;
                switch (strType)
                {
                case "message":
                    _messages.Add(new Slack.Messages.Text(_client, message));
                    break;

                default:
                    _messages.Add(new Slack.Messages.Unknown(message));
                    break;
                }
            }
        }
示例#9
0
 public IM(Slack.Client Client)
 {
     _client = Client;
 }
 public UserTypingEventArgs(Slack.Client Client, dynamic Data)
 {
     _client  = Client;
     _channel = Data.channel;
     _user    = Data.user;
 }
 public DoNotDisturbUpdatedUserEventArgs(Slack.Client Client, dynamic Data)
 {
     _client     = Client;
     _dnd_status = new DoNotDisturbUserStatus(Data.dnd_status);
     _user       = Data.user;
 }
示例#12
0
 public DND(Slack.Client Client)
 {
     _client = Client;
 }
 public IM(Slack.Client client)
 {
     _client = client;
 }
示例#14
0
 public Chat(Slack.Client Client)
 {
     _client = Client;
 }
示例#15
0
 public PresenceChangeEventArgs(Slack.Client Client, dynamic Data)
 {
     _client   = Client;
     _presence = Utility.TryGetProperty(Data, "presence");
     _user     = Utility.TryGetProperty(Data, "user");
 }
 public Collection(Slack.Client Client)
 {
     _client = Client;
 }
 public PostMessageResponse(Slack.Client client, dynamic Response)
 {
     channel = Utility.TryGetProperty(Response, "channel");
     ts      = new Slack.TimeStamp(Utility.TryGetProperty(Response, "ts"));
     message = new Slack.Messages.Text(client, Response.message);
 }