Skip to content

Commit

Permalink
Update ImagemapSampleApp
Browse files Browse the repository at this point in the history
  • Loading branch information
implem-kobayashi committed Nov 13, 2018
1 parent 8517079 commit d3da3e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
26 changes: 24 additions & 2 deletions FunctionAppSample/Samples/ImagemapSampleApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Azure.WebJobs.Host;
using System;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;

namespace FunctionAppSample
Expand Down Expand Up @@ -31,12 +32,16 @@ protected override async Task OnMessageAsync(MessageEvent ev)
case EventMessageType.Image:
await ReplyImagemapAsync(ev.ReplyToken, ev.Message.Id, ev.Source.Type + "_" + ev.Source.Id);
break;
case EventMessageType.Video:
await UploadVideoAsync(ev.ReplyToken, ev.Message.Id ,ev.Source.Type + "_" + ev.Source.Id);
break;
case EventMessageType.Text:
await MessagingClient.ReplyMessageAsync(ev.ReplyToken, ((TextEventMessage)ev.Message).Text);
break;
}
}


private async Task ReplyImagemapAsync(string replyToken, string messageId, string blobDirectoryName)
{
var imageStream = await MessagingClient.GetContentStreamAsync(messageId);
Expand All @@ -56,6 +61,14 @@ private async Task ReplyImagemapAsync(string replyToken, string messageId, strin
var imageSize = new ImagemapSize(1024, (int)(1040 * (double)image.Height / image.Width));
var areaWidth = imageSize.Width / 2;
var areaHeight = imageSize.Height / 2;
Video video = null;
var videoUrl = BlobStorage.ListBlobUri(blobDirectoryName).FirstOrDefault(x => x.ToString().EndsWith("video.mp4"));
if (videoUrl!=null)
{
video = new Video(videoUrl.ToString(), videoUrl.ToString().Replace("video.mp4","300"),
new ImagemapArea(0, 0, areaWidth, areaHeight),
new ExternalLink("https://google.com", "google"));
}
var imagemapMessage = new ImagemapMessage(uri.ToString().Replace("/1040", ""),
"Sample Imagemap",
imageSize,
Expand All @@ -64,16 +77,25 @@ private async Task ReplyImagemapAsync(string replyToken, string messageId, strin
new MessageImagemapAction(new ImagemapArea(areaWidth, 0, areaWidth,areaHeight),"Area Top-Right"),
new MessageImagemapAction(new ImagemapArea(0, areaHeight, areaWidth,areaHeight),"Area Bottom-Left"),
new MessageImagemapAction(new ImagemapArea(areaWidth, areaHeight, areaWidth,areaHeight),"Area Bottom-Right"),
});
},
video: video);

await MessagingClient.ReplyMessageAsync(replyToken, new[] { imagemapMessage });

async Task<Uri> UploadImageAsync(int baseSize)
{
var img = image.GetThumbnailImage(baseSize, image.Height * baseSize / image.Width, () => false, IntPtr.Zero);
return await BlobStorage.UploadImageAsync(img, blobDirectoryName + "/" + messageId, baseSize.ToString());
return await BlobStorage.UploadImageAsync(img, blobDirectoryName, baseSize.ToString());
}
}

private async Task UploadVideoAsync(string replyToken, string messageId, string blobDirectoryName)
{
var videoStream = await MessagingClient.GetContentStreamAsync(messageId);
var url = await BlobStorage.UploadFromStreamAsync(videoStream, blobDirectoryName, "video.mp4");

await MessagingClient.ReplyMessageAsync(replyToken, url.ToString());
}

}
}
1 change: 1 addition & 0 deletions Line.Messaging/Messages/ImagemapMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public ImagemapMessage(string baseUrl, string altText, ImagemapSize baseSize, IL
BaseSize = baseSize;
Actions = actions;
QuickReply = quickReply;
Video = video;
}
}
}

0 comments on commit d3da3e3

Please sign in to comment.