예제 #1
0
 // tag::Process[]
 public void Process(ViberIncoming incoming)
 {
     if (incoming?.Message?.Type == "text")
     {
         LogIncoming(incoming);
         ProcessMessage(incoming);
     }
 }
예제 #2
0
        // end::Process[]

        private void LogIncoming(ViberIncoming incoming)
        {
            // generate a unique key of the form "incoming::{random string}"
            var key = "incoming::" + Path.GetRandomFileName().Replace(".", "");

            // log the timestampe, the message, and the sender
            _bucket.Insert(key, new
            {
                Timestamp = DateTime.Now,
                Message   = incoming.Message,
                Sender    = incoming.Sender
            });
        }
예제 #3
0
        private void ProcessMessage(ViberIncoming incoming)
        {
            // chat logic here
            // a more robust chat/natural language framework/tool would be
            // a better fit for complex chat logic

            // if message is "help" then provide help
            if (incoming.Message.Text.ToLower() == "help")
            {
                SendTextMessage(HelpMessage, incoming.Sender.Id);
            }
            // get "metrics" when asked for
            else if (incoming.Message.Text.ToLower().Contains("metrics"))
            {
                SendTextMessage(GetMetrics(), incoming.Sender.Id);
            }
            // get some flight information
            else if (incoming.Message.Text.ToLower().Contains("flights"))
            {
                ProcessFlightRequest(incoming.Message.Text, incoming.Sender.Id);
            }
            // if message contains "twitter" then return a random suggestion of who to follow on twitter
            else if (incoming.Message.Text.ToLower().Contains("twitter"))
            {
                SendTextMessage("I think you should follow https://twitter.com/" + TwitterSuggestions[Rand.Next(0, TwitterSuggestions.Count - 1)] + " on Twitter!", incoming.Sender.Id);
            }
            // tag::snippet[]
            // if the message contains "hi", "hello", etc say "howdy"
            else if (HelloStrings.Any(incoming.Message.Text.ToLower().Contains))
            {
                SendTextMessage("Howdy!", incoming.Sender.Id);
            }
            // if message contains "?" then link to the forums
            else if (incoming.Message.Text.Contains("?"))
            {
                SendTextMessage("If you have a Couchbase question, please ask on the forums! http://forums.couchbase.com", incoming.Sender.Id);
            }
            else
            {
                SendTextMessage("I'm sorry, I don't understand you. Type 'help' for help!", incoming.Sender.Id);
            }
            // end::snippet[]
        }