示例#1
0
        public static async Task GenerateCards(Conversation convo, string writeToken, string fileId)
        {
            var cards = new List <Dictionary <string, object> >();

            cards.AddRange(BoxHelper.GenerateTranscriptCard(convo, fileId));
            cards.AddRange(BoxHelper.GenerateTopicsKeywordCard(convo, fileId));
            await BoxHelper.UpdateSkillCards(cards, writeToken, fileId);
        }
示例#2
0
        public async Task <APIGatewayProxyResponse> FunctionHandler(System.IO.Stream request, ILambdaContext context)
        {
            Console.WriteLine("======== Skill Executing!! =========");

            string requestStr;

            using (StreamReader reader = new StreamReader(request)) {
                requestStr = reader.ReadToEnd();
            }
            dynamic requestJson = JObject.Parse(requestStr);
            dynamic inputJson   = JObject.Parse(requestJson.body.Value);
            string  fileId      = inputJson.source.id.Value;

            Console.WriteLine("======== Request String =========");
            Console.WriteLine(requestStr);
            Console.WriteLine("======== Context =========");
            Console.WriteLine(JsonConvert.SerializeObject(context, Formatting.None));
            Console.WriteLine("======== Box Input (body) =========");
            Console.WriteLine(JsonConvert.SerializeObject(inputJson, Formatting.None));
            var jobName = $"f{inputJson.source.id}";

            // move file to S3 for processing (aws can not process using anything other than an S3 uir)
            var fileUrl = BoxHelper.getFileUrl(fileId, inputJson.token);

            Console.WriteLine($"FileUrl: {fileUrl}");
            string fileExt  = Path.GetExtension(inputJson.source.name.Value).TrimStart('.');
            string fileName = $"{jobName}.{fileExt}";
            string mimeType = MimeMapping.GetMimeType(fileExt);

            PutObjectResponse response = await BoxHelper.UploadBoxFileToS3(fileUrl, config.S3BucketName, mimeType, fileName);

            Console.WriteLine("======== Put Object Response =========");
            Console.WriteLine(JsonConvert.SerializeObject(response, Formatting.None));
            if (response.HttpStatusCode.CompareTo(HttpStatusCode.OK) != 0)
            {
                return(GetResponse(response.HttpStatusCode, "Error uploading file to S3"));
            }

            Console.WriteLine("JobName: " + jobName);
            Conversation convo = await AWSHelper.TranscribeMedia(jobName, fileName, fileExt);

            await AWSHelper.DeleteObjectNonVersionedBucketAsync(fileName);

            //await BoxHelper.GenerateCards(result, inputJson);
            await GenerateCards(convo, inputJson.token.write.access_token.Value, fileId);

            return(GetResponse(HttpStatusCode.OK, "Success"));
        }