/// <summary>
        /// Converts a Bot Framework activity to a RingCentral message.
        /// </summary>
        /// <param name="activity">Activity to send to RingCentral.</param>
        /// <param name="sourceId">Id of the RingCentral source/channel where to send the activity to.</param>
        /// <returns>Id of the content generated.</returns>
        public virtual async Task <string> SendContentToRingCentralAsync(Activity activity, string sourceId)
        {
            _ = activity ?? throw new ArgumentNullException(nameof(activity));

            var config = RingCentralSdkHelper.InitializeRingCentralConfiguration(
                _options.CurrentValue.RingCentralEngageApiUrl,
                _options.CurrentValue.RingCentralEngageApiAccessToken);

            ContentsApi contentsApi = new ContentsApi(config);

            string messageBody = activity.Text;

            if (!string.IsNullOrEmpty(messageBody))
            {
                try
                {
                    var content = await contentsApi.CreateContentAsync(
                        body : activity.Text,
                        sourceId : sourceId,
                        _private : 1,
                        inReplyToId : activity.From.Id);

                    return(content.Id);
                }
                catch (ApiException exp)
                {
                    // {"message":"Can't reply to closed thread","error":"cant_reply_to_closed_thread","status":403}
                    if (exp.ErrorCode == 403)
                    {
                        _logger.LogWarning($"SendContentToRingCentralAsync: {exp.Message}");
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
 public ContentsApiTests()
 {
     instance = new ContentsApi();
 }