public async Task <bool> SendNewMessage(Message message)
        {
            bool result = false;

            UpdateMessageWithMessageCategories(message);
            try
            {
                MainPage.Log($"===== SEND MESSAGE {message.Id} =====", true);
                MainPage.Log($"Create DimeloClient");
                DimeloClient client = new DimeloClient(Settings.EndpointUrl, Settings.AccountToken);

                MainPage.Log($"Create MessageRequest");
                DimeloRequest request = new DimeloRequest();
                request.Action = RingCentral.Sdk.Models.CreateAction.Message;

                RingCentral.Sdk.Models.Message sdkMessage = new RingCentral.Sdk.Models.Message();
                sdkMessage.Id = message.Id;
                if (!string.IsNullOrWhiteSpace(message.ThreadId))
                {
                    sdkMessage.ThreadId = message.ThreadId;
                }
                if (!string.IsNullOrWhiteSpace(message.ReplyToId))
                {
                    sdkMessage.InReplyToId = message.ReplyToId;
                }
                sdkMessage.Categories = message.Categories.ToArray();
                if (message.Author != null)
                {
                    sdkMessage.Author            = new RingCentral.Sdk.Models.User();
                    sdkMessage.Author.Id         = message.Author.Id;
                    sdkMessage.Author.Firstname  = message.Author.FirstName;
                    sdkMessage.Author.Lastname   = message.Author.LastName;
                    sdkMessage.Author.Screenname = message.Author.ScreenName;
                    sdkMessage.Author.Email      = message.Author.Email;
                    sdkMessage.Author.CreatedAt  = message.Author.Created;
                    sdkMessage.Author.UpdatedAt  = message.Author.Updated;
                }
                sdkMessage.Body      = message.Body;
                sdkMessage.CreatedAt = message.Created;
                sdkMessage.UpdatedAt = message.Updated;
                request.Params       = sdkMessage;

                MainPage.Log("\n" + request.GetJson() + "\n");

                MainPage.Log($"Send request");
                string response = await client.SendAsync(request);

                MainPage.Log($"Response: {response}");
                result = true;
            }
            catch (Exception ex)
            {
                MainPage.Log($"\nERROR: {ex.Message}");
                MainPage.Log(ex.ToString());
            }
            return(result);
        }
        /// <summary>
        /// Forward bot message message to RingCentral API, ensure a full transcript log for both the user & bot messages
        /// are persisted in the RingCentral platform.
        /// </summary>
        /// <param name="activity">Activity to publish to RingCentral.</param>
        /// <remarks>
        /// Here we only deal with Activity.Text - additional DownRenderingMiddleware is applied to the pipleline before this
        /// method should be invoke, therefore converting any adaptive cards, herocards, buttons etc. to clear text in the text field.
        /// </remarks>
        /// <returns>Task.</returns>
        public async Task SendActivityToRingCentralAsync(Activity activity)
        {
            _ = activity ?? throw new ArgumentNullException(nameof(activity));

            _logger.LogTrace($"SendActivityToRingCentralAsync: ForeignThreadId: {RingCentralSdkHelper.BuildForeignThreadIdFromActivity(activity)}, ConversationId: {activity.Conversation.Id}, ChannelId: {activity.ChannelId}, ServiceUrl: {activity.ServiceUrl}");

            // Skip publishing messages to RingCentral when it's opted out
            if (!_options.CurrentValue.LogMessagesToRingCentral)
            {
                return;
            }

            // Avoid publishing messages coming from an agent (they're already on RingCentral)
            if (RingCentralSdkHelper.IsActivityFromRingCentralOperator(activity))
            {
                return;
            }

            // Avoid publishing messages without text
            if (string.IsNullOrWhiteSpace(activity.Text))
            {
                return;
            }

            DimeloRequest request = new DimeloRequest();

            request.Action = CreateAction.Message;
            request.Params = new Message()
            {
                Id       = activity.Id,
                ThreadId = RingCentralSdkHelper.BuildForeignThreadIdFromActivity(activity),
                Body     = activity.Text,
                Author   = new User()
                {
                    Id         = activity.From.Id,
                    CreatedAt  = DateTime.Now,
                    Screenname = string.IsNullOrEmpty(activity.From?.Name)
                        ? $"A {activity.ChannelId} user"
                        : activity.From.Name,
                    Puppetizable = true
                },
                InReplyToId = activity.Recipient.Id,

                // CONSIDER: Which actions required Human Handoff capability
                Actions = new List <rcSourceSdk.Models.Action>()
                {
                    rcSourceSdk.Models.Action.Create,
                    rcSourceSdk.Models.Action.Reply,
                    rcSourceSdk.Models.Action.List
                }
            };

            // Use RingCentral Client Source SDK as we need to pass the specific actions above
            // to allow an operator to take over the conversations
            await _ringCentralClient.SendAsync(request);
        }
        public async Task <bool> SendNewThread(Thread thread)
        {
            bool result = false;

            try
            {
                MainPage.Log($"===== CREATE THREAD {thread.DisplayName} =====", true);
                MainPage.Log($"Create DimeloClient");
                DimeloClient client = new DimeloClient(Settings.EndpointUrl, Settings.AccountToken);

                MainPage.Log($"Create ThreadRequest");
                DimeloRequest request = new DimeloRequest();
                request.Action = RingCentral.Sdk.Models.CreateAction.Thread;

                RingCentral.Sdk.Models.Thread sdkThread = new RingCentral.Sdk.Models.Thread();
                sdkThread.Id         = thread.Id;
                sdkThread.Title      = thread.Title;
                sdkThread.Body       = thread.Body;
                sdkThread.Categories = thread.Categories.ToArray();
                if (thread.Author != null)
                {
                    sdkThread.Author            = new RingCentral.Sdk.Models.User();
                    sdkThread.Author.Id         = thread.Author.Id;
                    sdkThread.Author.Firstname  = thread.Author.FirstName;
                    sdkThread.Author.Lastname   = thread.Author.LastName;
                    sdkThread.Author.Screenname = thread.Author.ScreenName;
                    sdkThread.Author.Email      = thread.Author.Email;
                    sdkThread.Author.CreatedAt  = thread.Author.Created;
                    sdkThread.Author.UpdatedAt  = thread.Author.Updated;
                }
                sdkThread.Format    = RingCentral.Sdk.Models.Formatting.Text;
                sdkThread.CreatedAt = thread.Created;
                sdkThread.UpdatedAt = thread.Updated;
                request.Params      = sdkThread;

                MainPage.Log("\n" + request.GetJson() + "\n");

                MainPage.Log($"Send request");
                string response = await client.SendAsync(request);

                MainPage.Log($"Response: {response}");
                result = true;
            }
            catch (Exception ex)
            {
                MainPage.Log($"\nERROR: {ex.Message}");
                MainPage.Log(ex.ToString());
            }
            return(result);
        }
        public async Task <bool> SendNewUser(User user)
        {
            bool result = false;

            try
            {
                MainPage.Log($"===== CREATE USER {user.DisplayName} =====", true);
                MainPage.Log($"Create DimeloClient");
                DimeloClient client = new DimeloClient(Settings.EndpointUrl, Settings.AccountToken);

                MainPage.Log($"Create UserRequest");
                DimeloRequest request = new DimeloRequest();
                request.Action = RingCentral.Sdk.Models.CreateAction.User;

                RingCentral.Sdk.Models.User sdkUser = new RingCentral.Sdk.Models.User();
                sdkUser.Id         = user.Id;
                sdkUser.Firstname  = user.FirstName;
                sdkUser.Lastname   = user.LastName;
                sdkUser.Screenname = user.ScreenName;
                sdkUser.Email      = user.Email;
                sdkUser.CreatedAt  = user.Created;
                sdkUser.UpdatedAt  = user.Updated;
                request.Params     = sdkUser;

                MainPage.Log("\n" + request.GetJson() + "\n");

                MainPage.Log($"Send request");
                string response = await client.SendAsync(request);

                MainPage.Log($"Response: {response}");
                result = true;
            }
            catch (Exception ex)
            {
                MainPage.Log($"\nERROR: {ex.Message}");
                MainPage.Log(ex.ToString());
            }
            return(result);
        }