public static async void LineReply([ActivityTrigger] IDurableActivityContext context, ILogger log) { var input = context.GetInput <(string ReplyToken, string message)>(); var res = new LineTextResponseInterface(); try { res.ReplyToken = input.ReplyToken; res.Messages = new List <TextMessages>() { new TextMessages { Type = "text", Text = input.message, } }; var httpClient = HttpStart.GetInstance(); await httpClient.PostLineJsonAsync <LineTextResponseInterface>("https://api.line.me/v2/bot/message/reply", res); } catch (Exception ex) { log.LogError(ex.Message); throw; } }
public static async void LinePush([ActivityTrigger] IDurableActivityContext context, ILogger log) { var input = context.GetInput <(string UserId, string url, string score)>(); var res = new LineTemplateResponseInterface(); try { res.To = input.UserId; res.Messages = new List <TemplateMessages>() { new TemplateMessages { Type = "template", AltText = "写真のハピネス数値", Template = new Template() { Type = "buttons", ThumbnailImageUrl = input.url, Title = $"{input.score} pt", Text = $"この写真のハピネス数値です!", Actions = new List <Actions>() { new Actions { Type = "uri", Label = "ランキングを確認", Uri = AppSettings.Instance.LINE_POST_LIST, } } } } }; var httpClient = HttpStart.GetInstance(); await httpClient.PostLineJsonAsync <LineTemplateResponseInterface>("https://api.line.me/v2/bot/message/push", res); } catch (Exception ex) { log.LogError(ex.Message); throw; } }
public static async Task <string> UploadFileToStorage([ActivityTrigger] string id, ILogger log) { // Blob取得オプション BlobRequestOptions options = new BlobRequestOptions { ParallelOperationThreadCount = 8, // 同時にアップロードできるブロックの数 DisableContentMD5Validation = true, // BLOBのダウンロード時にMD5検証を無効にする StoreBlobContentMD5 = false // アップロードするときにMD5ハッシュを計算して保存しない }; try { var credential = new StorageCredentials(AppSettings.Instance.STORAGE_ACCOUNT_NAME, AppSettings.Instance.STORAGE_ACCESS_KEY); CloudStorageAccount storageAccount = new CloudStorageAccount(credential, true); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(AppSettings.Instance.BLOB_NAME); await container.CreateIfNotExistsAsync(); await container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); var filename = id + ".jpg"; CloudBlockBlob blockBlob = container.GetBlockBlobReference(filename); var client = HttpStart.GetInstance(); var stream = await client.GetStreamAsync($"https://api.line.me/v2/bot/message/{id}/content"); await blockBlob.UploadFromStreamAsync(stream, null, options, null); var blobUrl = blockBlob.Uri.AbsoluteUri; return(blobUrl); } catch (Exception ex) { log.LogError(ex.Message); throw; } }
public static async void RegisterToCosmosdb([ActivityTrigger] IDurableActivityContext context, ILogger log) { var feedOptions = new FeedOptions { MaxItemCount = 1, EnableCrossPartitionQuery = true }; var input = context.GetInput <(string user_id, string url, string score, string image_id)>(); var httpClient = HttpStart.GetInstance(); var userInfo = await httpClient.GetAsync($"https://api.line.me/v2/bot/profile/{input.user_id}"); var data = JsonConvert.DeserializeObject <LineUserInfoInterface>(userInfo); TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time"); var item = new DocumentInterface() { ImageId = input.image_id, User = data.Name, UserIcon = data.PictureUrl, PictureUrl = input.url.Replace(AppSettings.Instance.BLOB_URL, AppSettings.Instance.PROXY_URL), Score = double.Parse(input.score), GoodCnt = 0, CreatedDatatime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.ToUniversalTime(), tst), UpdatedDatatime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.ToUniversalTime(), tst) }; var ducumentClient = HttpStart.GetDocumentInstance(); await ducumentClient.CreateDatabaseIfNotExistsAsync(new Database { Id = AppSettings.Instance.DATABASE_ID }); PartitionKeyDefinition pkDefn = new PartitionKeyDefinition() { Paths = new Collection <string>() { "/image_id" } }; await ducumentClient.CreateDocumentCollectionIfNotExistsAsync( UriFactory.CreateDatabaseUri(AppSettings.Instance.DATABASE_ID), new DocumentCollection { Id = AppSettings.Instance.COLLECTION_ID, PartitionKey = pkDefn }, new RequestOptions { OfferThroughput = 400, PartitionKey = new PartitionKey("/image_id") }); await ducumentClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(AppSettings.Instance.DATABASE_ID, AppSettings.Instance.COLLECTION_ID), item); var documentQuery = ducumentClient.CreateDocumentQuery <DocumentInterface>(UriFactory.CreateDocumentCollectionUri(AppSettings.Instance.DATABASE_ID, AppSettings.Instance.COLLECTION_ID), feedOptions) .OrderByDescending(x => x.Score) .ToList(); var rank = new RankResponseInterface(); rank.Images = new List <Images>(); var count = 0; foreach (var res in documentQuery) { var image = new Images { ImageId = res.ImageId, User = res.User, UserIcon = res.UserIcon, PictureUrl = res.PictureUrl, Score = res.Score, GoodCnt = res.GoodCnt, Rank = count += 1 }; rank.Images.Add(image); } await httpClient.PostJsonAsync <RankResponseInterface>(AppSettings.Instance.SIGNALR_URL, rank); }