Esempio n. 1
0
        /// <summary>
        /// Handles the messaging asynchronous.
        /// </summary>
        /// <param name="messages">The messages.</param>
        /// <returns></returns>
        private async Task HandleMessagingAsync(List <Messaging> messages)
        {
            foreach (var messaging in messages)
            {
                if (messaging.Message != null && !messaging.Message.IsEcho)
                {
                    /// User Send Message
                    /// This callback will occur when a message has been sent to your page.You may receive text messages or messages
                    /// with attachments(image, audio, video, file or location).Callbacks contain a seq number which can be used
                    /// to know the sequence of a message in a conversation. Messages are always sent in order.
                    /// You can subscribe to this callback by selecting the message field when setting up your webhook.

                    var userProfile = await _clientMessenger.GetUserProfileAsync(messaging.Sender.Id);

                    if (userProfile != null)
                    {
                        RILogManager.Default.SendJSON("userProfile", userProfile);

                        var result = await _clientMessenger.SendMessageAsync(messaging.Sender.Id, new TextMessage
                        {
                            Text = $"Hi, {userProfile.Firstname}. An agent will respond to your question shortly."
                        });

                        RILogManager.Default.SendJSON("Results", new[] { result });
                    }
                }
                else if (messaging.Postback != null)
                {
                }
                else if (messaging.Delivery != null)
                {
                    /// This callback will occur when a message a page has sent has been delivered.
                    /// You can subscribe to this callback by selecting the message_deliveries field when setting up your webhook.
                }
                else if (messaging.Read != null)
                {
                    /// This callback will occur when a message a page has sent has been read by the user.
                    /// You can subscribe to this callback by selecting the message_reads field when setting up your webhook.
                }
                else if (messaging.Optin != null)
                {
                    /// User Call "Message Us"
                }
                else if (messaging.Referral != null)
                {
                    /// Referral
                }
                else if (messaging.AccountLinking != null)
                {
                    /// Account Linking
                }
            }
        }
        private static async Task SendSimpleMessageAync(ClientMessenger client, string userId)
        {
            var result1 = await client.SendMessageAsync(userId, new TextMessage("Hi there Ross - 4!"));

            // typing on/off
            var result2 = await client.SendActionAsync(userId, SenderAction.TypingOn);

            await Task.Delay(10000);

            var result3 = await client.SendActionAsync(userId, SenderAction.TypingOff);

            var userProfile = await client.GetUserProfileAsync(userId);

            // set greeting - on first attaching
            var result10 = await client.SetGreetingTextAsync("Welcome to Hubster");

            // clear greeting
            var result11 = await client.SetGreetingTextAsync();
        }