Example #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="directLineSecret">The Direct Line secret associated with the bot.</param>
        /// <param name="consumerKey">The Twitter consumer key.</param>
        /// <param name="consumerSecret">The Twitter consumer secret.</param>
        /// <param name="bearerToken"></param>
        /// <param name="accessToken">The Twitter app access token.</param>
        /// <param name="accessTokenSecret">The Twitter app secret.</param>
        /// <param name="conversationCache">A message and user ID cache implementation.</param>
        public TwitterBotIntegrationManager(
            string directLineSecret,
            string consumerKey, string consumerSecret,
            string bearerToken = null,
            string accessToken = null, string accessTokenSecret = null,
            IDirectLineConversationCache directLineConversationCache = null,
            ITweetConversationCache tweetConversationCache           = null)
        {
            _directLineManager = new DirectLineManager(directLineSecret, directLineConversationCache ?? new InMemoryConversationCache());
            _twitterManager    = new TwitterManager(consumerKey, consumerSecret, bearerToken, accessToken, accessTokenSecret);
            _conversationCache = tweetConversationCache ?? new InMemoryConversationCache();

            _directLineManager.ActivitiesReceived += OnActivitiesReceived;
            _twitterManager.TweetReceived         += OnTweetReceivedAsync;
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="directLineSecret">The Direct Line secret associated with the bot.</param>
        public DirectLineManager(string directLineSecret, IDirectLineConversationCache conversationCache)
        {
            if (string.IsNullOrEmpty(directLineSecret))
            {
                throw new ArgumentNullException("Direct Line secret is null or empty");
            }
            if (conversationCache == null)
            {
                throw new ArgumentNullException("conversationCache is null");
            }

            _backgroundWorker                     = new BackgroundWorker();
            _backgroundWorker.DoWork             += new DoWorkEventHandler(RunPollMessagesLoopAsync);
            _backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackgroundWorkerDone);

            _directLineSecret  = directLineSecret;
            _conversationCache = conversationCache;
        }