Beispiel #1
0
        public static void EntryPoint(JToken postback)
        {
            var parsedPostBack = JObject.Parse((string)postback);
            var userId         = (string)parsedPostBack["recipient"]["id"];

            if ((string)parsedPostBack["intent"] == "SegmentInfo")
            {
                var    currency = new UserHandler().GetCurrency(userId) ?? "USD";
                string currencyCulture;
                Currency.currencies.TryGetValue(currency, out currencyCulture);

                var origin    = (string)parsedPostBack["origin"];
                var dest      = (string)parsedPostBack["destination"];
                var routeName = (string)parsedPostBack["routeName"];
                var location  = (string)parsedPostBack["location"];

                var oPos = false;
                var dPos = false;
                if (origin.Equals("here", StringComparison.InvariantCultureIgnoreCase) ||
                    origin.Equals("my location", StringComparison.InvariantCultureIgnoreCase))
                {
                    oPos = true;
                }
                if (dest.Equals("here", StringComparison.InvariantCultureIgnoreCase) ||
                    dest.Equals("my location", StringComparison.InvariantCultureIgnoreCase))
                {
                    dPos = true;
                }

                var segments = ConstructSegmentObjects(origin, dest, routeName, oPos, dPos, location, currency);
                if (segments != null)
                {
                    var message = ConstructSegmentJson(segments, currencyCulture);
                    MessageHandler.SenderId = userId;
                    MessageHandler.SendCustomMessage(message);
                }
            }
            else if ((string)parsedPostBack["intent"] == "SendMap")
            {
                var url = (string)parsedPostBack["MapUrl"];

                var p = new JObject(
                    new JProperty("url", url)
                    );
                var att = new JObject(
                    new JProperty("type", "image"),
                    new JProperty("payload", p)
                    );
                var message = new JObject(
                    new JProperty("attachment", att)
                    );
                MessageHandler.SenderId = userId;
                MessageHandler.SendAttachment(message.ToString(Formatting.None));
            }
        }
Beispiel #2
0
        public static async Task <string> EntryPoint(string origin, string dest, string currency)
        {
            bool oPos = false;
            bool dPos = false;

            if (origin.Equals("here", StringComparison.InvariantCultureIgnoreCase) ||
                origin.Equals("my location", StringComparison.InvariantCultureIgnoreCase))
            {
                oPos = true;
            }
            if (dest.Equals("here", StringComparison.InvariantCultureIgnoreCase) ||
                dest.Equals("my location", StringComparison.InvariantCultureIgnoreCase))
            {
                dPos = true;
            }

            if (oPos && dPos)
            {
                MessageHandler.SendTextMessage("You are searching between the same two points!");
                return(string.Empty);
            }
            var routes = ConstructRouteObjects(origin, dest, oPos, dPos, currency);

            if (routes != null)
            {
                var message = ConstructJsonFromRoutes(routes, currency, origin, dest, oPos || dPos);

                //var message = GetDescription(origin, dest);

                await MessageHandler.SendCustomMessage(message);
            }
            else
            {
                if (!oPos && !dPos)
                {
                    await MessageHandler.SendTextMessage("I am sorry I could not resolve your search query. Please check your response and try again");
                }
            }
            return(string.Empty);
        }