Ejemplo n.º 1
0
        private static async Task sendGifMessage(string recipientId, string messageText)
        {
            string tagString = messageText.Substring(3).Trim();

            string gifUrl = await GifGetter.New(tagString);

            var message = new OutboundMessaging
            {
                recipient = new Participant
                {
                    id = recipientId
                },
                message = new OutboundMessage
                {
                    attachment = new Attachment
                    {
                        type    = "image",
                        payload = new Payload
                        {
                            url = gifUrl
                        }
                    }
                }
            };

            MessageSender.Send(message).Wait();
        }
Ejemplo n.º 2
0
        public static async Task Send(OutboundMessaging message)
        {
            using (var client = new HttpClient())
            {
                var content = new StringContent(JsonConvert.SerializeObject(message), System.Text.Encoding.UTF8, "application/json");

                var accessToken = Environment.GetEnvironmentVariable("fb_token");

                if (string.IsNullOrEmpty(accessToken))
                {
                    throw new Exception("You need to set the access token for the Messenger API in the environment variables.");
                }

                var url = "https://graph.facebook.com/v2.6/me/messages?access_token=" + accessToken;

                try
                {
                    var response = await client.PostAsync(url, content);

                    Console.WriteLine("Status: " + response.StatusCode);

                    if (response.Content != null)
                    {
                        var responseString = await response.Content.ReadAsStringAsync();

                        Console.WriteLine(responseString);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Message send failed: " + ex.Message);
                }
            }
        }
Ejemplo n.º 3
0
        private static async Task sendRadarMessage(string recipientId, string messageText)
        {
            string filter = messageText.Substring(5).Trim();

            List <string> imageUrls = await RadarGetter.Get(filter);

            imageUrls = imageUrls.OrderByDescending(u => u).Take(3).OrderBy(u => u).ToList();

            foreach (var imageUrl in imageUrls)
            {
                var message = new OutboundMessaging
                {
                    recipient = new Participant
                    {
                        id = recipientId
                    },
                    message = new OutboundMessage
                    {
                        attachment = new Attachment
                        {
                            type    = "image",
                            payload = new Payload
                            {
                                url = imageUrl
                            }
                        }
                    }
                };

                Console.WriteLine("Sending message with url: " + imageUrl);
                MessageSender.Send(message).Wait();
            }
        }
Ejemplo n.º 4
0
        private static void sendThereforeMessage(string recipientId, string messageText)
        {
            var message = new OutboundMessaging
            {
                recipient = new Participant
                {
                    id = recipientId
                },
                message = new OutboundMessage
                {
                    text = "...therefore I am."
                }
            };

            MessageSender.Send(message).Wait();
        }
Ejemplo n.º 5
0
        private void sendDefaultMessage(string recipientId, string messageText)
        {
            var response = @"Hi there - you can ask me what the weather will be like in Wellington by typing 'weather', or find the next departing train from your station by typing 'train' followed by the name of the station - e.g. 'train Silverstream'.";

            var message = new OutboundMessaging
            {
                recipient = new Participant
                {
                    id = recipientId
                },
                message = new OutboundMessage
                {
                    text = response
                }
            };

            MessageSender.Send(message).Wait();
        }
Ejemplo n.º 6
0
        private static async Task sendWeatherMessage(string recipientId, string messageText)
        {
            string filter = messageText.Substring(7).Trim();

            string weather = await WeatherGetter.Get(filter);

            var message = new OutboundMessaging
            {
                recipient = new Participant
                {
                    id = recipientId
                },
                message = new OutboundMessage
                {
                    text = weather
                }
            };

            MessageSender.Send(message).Wait();
        }
Ejemplo n.º 7
0
        private static async Task sendBusMessage(string recipientId, string messageText)
        {
            string stop = messageText.Substring(3).Trim();

            string nextDeparture = await BusGetter.Get(stop);

            var message = new OutboundMessaging
            {
                recipient = new Participant
                {
                    id = recipientId
                },
                message = new OutboundMessage
                {
                    text = nextDeparture
                }
            };

            MessageSender.Send(message).Wait();
        }