/// <summary>
        /// Initializes a new instance of the <see cref="InfobipWhatsAppAdapter"/> class using configuration settings.
        /// </summary>
        /// <param name="infobipWhatsAppOptions">Adapter options. Typically created via appsettings loaded into an IConfiguration.</param>
        /// <param name="infobipWhatsAppClient">Client/Proxy used to communicate with Infobip.</param>
        /// <param name="logger">Logger.</param>
        public InfobipWhatsAppAdapter(InfobipWhatsAppAdapterOptions infobipWhatsAppOptions, IInfobipWhatsAppClient infobipWhatsAppClient, ILogger <InfobipWhatsAppAdapter> logger)
        {
            _whatsAppAdapterOptions = infobipWhatsAppOptions ?? throw new ArgumentNullException(nameof(infobipWhatsAppOptions));
            _infobipWhatsAppClient  = infobipWhatsAppClient ?? throw new ArgumentNullException(nameof(infobipWhatsAppClient));
            _logger = logger ?? NullLogger <InfobipWhatsAppAdapter> .Instance;

            _toWhatsAppActivityConverter = new ToWhatsAppActivityConverter(_whatsAppAdapterOptions, _infobipWhatsAppClient, _logger);
            _authorizationHelper         = new AuthorizationHelper();
        }
 public ToWhatsAppActivityConverter(InfobipWhatsAppAdapterOptions whatsAppAdapterOptions, IInfobipWhatsAppClient infobipWhatsAppClient, ILogger logger)
 {
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
     _whatsAppAdapterOptions = whatsAppAdapterOptions ?? throw new ArgumentNullException(nameof(whatsAppAdapterOptions));
     _infobipWhatsAppClient  = infobipWhatsAppClient ?? throw new ArgumentNullException(nameof(infobipWhatsAppClient));
 }
        public static async Task <Activity> Convert(InfobipWhatsAppIncomingResult result, IInfobipWhatsAppClient infobipWhatsAppClient)
        {
            var activity = ConvertToMessage(result);

            activity.ChannelId = InfobipWhatsAppConstants.ChannelName;

            if (result.Message.Type == InfobipIncomingMessageTypes.Text)
            {
                activity.Text       = result.Message.Text;
                activity.TextFormat = TextFormatTypes.Plain;
            }
            else if (result.Message.Type == InfobipIncomingMessageTypes.Location)
            {
                activity.Entities.Add(new GeoCoordinates
                {
                    Latitude  = result.Message.Latitude,
                    Longitude = result.Message.Longitude
                });
            }
            else if (result.Message.IsMedia())
            {
                var contentType = await infobipWhatsAppClient.GetContentTypeAsync(result.Message.Url.AbsoluteUri).ConfigureAwait(false);

                activity.Attachments = new List <Attachment>
                {
                    new Attachment
                    {
                        ContentType = contentType,
                        ContentUrl  = result.Message.Url.AbsoluteUri,
                        Name        = result.Message.Caption
                    }
                };
            }
            else
            {
                return(null);
            }

            return(activity);
        }