示例#1
0
        public RestClient GetClient(string baseUrl)
        {
            var credentials = new AwsApiKey()
            {
                AccessKey = "", // fill in your IAM API Token Access Key
                SecretKey = "", // fill in your IAM API Token Secret Key
                Region    = ""  // fill in your service region
            };

            return(new RestClient(baseUrl)
            {
                Authenticator = new Sig4Authenticator(credentials)
            });
        }
示例#2
0
        private async Task ForwardCueResponseAsync(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            try
            {
                if (turnContext != null && turnContext.Activity.ChannelData is JObject channelData)
                {
                    if (!string.IsNullOrWhiteSpace(_syntinelBaseUrl) &&
                        !string.IsNullOrWhiteSpace(_syntinelSlackCueUrl) &&
                        !string.IsNullOrWhiteSpace(_awsRegion) &&
                        !string.IsNullOrWhiteSpace(_awsAccessKey) &&
                        !string.IsNullOrWhiteSpace(_awsSecretKey))
                    {
                        var       client = new RestClient(_syntinelBaseUrl);
                        AwsApiKey apiKey = new AwsApiKey()
                        {
                            Region    = _awsRegion,
                            AccessKey = _awsAccessKey,
                            SecretKey = _awsSecretKey,
                        };
                        client.Authenticator = new Sig4Authenticator(apiKey);

                        var relativeUrl = string.Empty;
                        var jsonString  = string.Empty;

                        switch (turnContext.Activity.ChannelId)
                        {
                        case "slack":
                            relativeUrl = _syntinelSlackCueUrl;
                            jsonString  = channelData.ToString(Formatting.Indented);
                            break;

                        case "msteams":
                            relativeUrl = _syntinelTeamsCueUrl;
                            jsonString  = turnContext.Activity.Value?.ToString();
                            break;

                        default:
                            break;
                        }

                        if (!string.IsNullOrWhiteSpace(_syntinelBaseUrl) && !string.IsNullOrWhiteSpace(relativeUrl) && !string.IsNullOrWhiteSpace(jsonString))
                        {
                            string answer = "Your response is being processed.";
                            await turnContext.SendActivityAsync(answer, cancellationToken : cancellationToken);

                            var request = new RestRequest();
                            request.AddParameter("application/json", jsonString, ParameterType.RequestBody);
                            request.Method   = Method.POST;
                            request.Resource = relativeUrl;

                            _logger.LogInformation($"Sending below cue response to Syntinel:\n{jsonString}");
                            client.ExecuteAsync(request, response =>
                            {
                                _logger.LogInformation(response.Content);
                            });
                        }
                        else
                        {
                            _logger.LogError("Valid Syntinel cue response url is not specified.");
                        }
                    }
                    else
                    {
                        _logger.LogError("Unable to post user response to Syntinel. Please check for missing configurations.");
                    }
                }
                else
                {
                    _logger.LogError("Unable to obtain channel data from turn context.");
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
            }
        }