Skip to content

Instantly share code, notes, and snippets.

@tderick
Created October 8, 2021 13:26
Show Gist options
  • Save tderick/e54281f7253a99c68ae28f384aed829e to your computer and use it in GitHub Desktop.
Save tderick/e54281f7253a99c68ae28f384aed829e to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:sigv4/sigv4.dart';
class BotService {
String? result;
String botName = "TestLex";
String kAccessKeyId = 'AKIAWHPGDPDTHWH6ZH4T';
String kSecretAccessKey = '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';
String botAlias = "version_a";
String botAWSRegion = "eu-central-1";
void callBot(String message) async {
// var response;
String requestUrl = "https://runtime.lex." +
botAWSRegion +
".amazonaws.com/bot/" +
botName +
"/alias/" +
botAlias +
"/user/1234/text";
Sigv4Client client = Sigv4Client(
region: botAWSRegion,
serviceName: 'lex',
defaultContentType: 'application/json; charset=utf-8',
keyId: kAccessKeyId,
accessKey: kSecretAccessKey,
);
final request = client.request(
requestUrl,
method: 'POST',
body: jsonEncode({'inputText': message}),
);
var response = await http.post(request.url,
headers: request.headers, body: request.body);
result = jsonDecode(response.body);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment