public async Task ProcessIntent(AIResponse aIResponse) { AccessToken accessToken = await _tokenManager.GetAccessTokenFromCache().ConfigureAwait(false); _lineMessagingClient = new LineMessagingClient(accessToken.access_token); var app = new LineBotApp(_lineMessagingClient); // try case IntentName to IntentType Enum IntentType intentType = IntentType.Unknown; if (Enum.TryParse <IntentType>(aIResponse.Result.Metadata.IntentName, out intentType)) { aIResponse.Result.Metadata.IntentType = intentType; } Event tempEvent = new Event(); switch (aIResponse.Result.Metadata.IntentType) { case IntentType.ButtonIntent: // Down Cast tempEvent = aIResponse.OriginalRequest.Event; MessageEvent messageEventTemp = (MessageEvent)tempEvent; TextEventMessage eventMessageTemp = (TextEventMessage)messageEventTemp.Message; eventMessageTemp.Text = "buttons"; break; default: break; } await app.RunAsync(new List <WebhookEvent>(){ (WebhookEvent)tempEvent }); }
public LineBotApp(LineMessagingClient lineMessagingClient, TableStorage <EventSourceState> tableStorage, BlobStorage blobStorage, TraceWriter log) { MessagingClient = lineMessagingClient; SourceState = tableStorage; BlobStorage = blobStorage; Log = log; }
public override void Configure(IFunctionsHostBuilder builder) { builder.Services .AddSingleton <Settings>() .AddSingleton <LineBotApp>(s => new LineBotApp(LineMessagingClient.Create(s.GetService <Settings>().ChannelAccessToken), s.GetService <Settings>())); }
private void button1_Click(object sender, EventArgs e) { var message = $"商品が見つかりました。\n下記URLから商品購入を行ってください。\nhttps://www.toysrus.co.jp/search/?q=4902370537789"; LineMessagingClient lineMessagingClient = new LineMessagingClient("42ndcVVsa4VFSJD9vtyuslUG6VLkWz+i96cu5AFJlsjdOgyQx0SZO0k/4sDu7dE7iFoMl34+qBkUKnjecyjWDItkpWmIOtAxGGupCH/93zeKW/jsY4oS5UDXkBPYZunZxlbP8Qv2wH9slZLA5N+3ZAdB04t89/1O/w1cDnyilFU="); lineMessagingClient.PushMessageAsync("U40ab91bbe212e2256a52157bf13c5705", message); }
public LineBotApp(string text, LineMessagingClient lineMessagingClient, TableStorage <EventSourceState> tableStorage, BlobStorage blobStorage) { this.text = text; this.messagingClient = lineMessagingClient; this.sourceState = tableStorage; this.blobStorage = blobStorage; }
//メンバーの名前を更新 public async Task UpdateMember() { var lineMessagingClient = new LineMessagingClient(Environment.GetEnvironmentVariable("CHANNEL_ACCESS_TOKEN")); var iterator = container.GetItemQueryIterator <Member>("SELECT * FROM c WHERE c.leavedDate = null"); do { var result = await iterator.ReadNextAsync(); foreach (var item in result) { var user = lineMessagingClient.GetGroupMemberProfileAsync(GroupId, item.id); var NewerName = user.Result.DisplayName; if (NewerName != item.newername) { var m = new Member { id = item.id, name = item.name, newername = NewerName, joinedDate = item.joinedDate, check = item.check, postScript = item.postScript, leavedDate = item.leavedDate }; await container.UpsertItemAsync(m); } } } while (iterator.HasMoreResults); }
static HttpTriggerFunction() { lineMessagingClient = new LineMessagingClient(Environment.GetEnvironmentVariable("ChannelAccessToken")); var sp = ServicePointManager.FindServicePoint(new Uri("https://api.line.me")); sp.ConnectionLeaseTimeout = 60 * 1000; }
public LineBotApp(string channelId, LineMessagingClient messagingClient, CloudTable accountTable, ILogger log) { this.channelId = channelId; this.messagingClient = messagingClient; this.accountTable = accountTable; this.log = log; }
public async Task ReturnUserInfoIfValidDataReturnedFromApi() { // Arrange // Mock Dependencies ILineHttpClient fakeLineHttpClient = A.Fake <ILineHttpClient>(); //Initialize ILineMessagingClient realLineMessagingClient = new LineMessagingClient(fakeLineHttpClient); //Mock Data string fakeResponseData = @"{ ""displayName"" : ""user"", ""userId"" : ""test"", ""pictureUrl"" : ""img"", ""statusMessage"" : ""busy"", }"; byte[] fakeResponse = Encoding.ASCII.GetBytes(fakeResponseData); A.CallTo(() => fakeLineHttpClient.GetProfileAsync("test")).Returns(Task.FromResult(fakeResponse)); // Act var testResult = await realLineMessagingClient.GetUserInfoAsync("test"); // Assert A.CallTo(() => fakeLineHttpClient.GetProfileAsync("test")).MustHaveHappened(); Assert.Equal("user", testResult.displayName); Assert.Equal("test", testResult.userId); Assert.Equal("img", testResult.pictureUrl); Assert.Equal("busy", testResult.statusMessage); }
public LineBotApp(LineMessagingClient messagingClient, TableStorage <EventSourceState> tableStorage, BlobStorage blobStorage, TraceWriter log) { this.messagingClient = messagingClient; this.sourceState = tableStorage; this.blobStorage = blobStorage; this.log = log; }
public TalkManager(BingoBotTableStorage tableStorage, BingoBotBlobStorage blobStrorage, LineMessagingClient messagingClient, TraceWriter log) { _tableStorage = tableStorage; _blobStorage = blobStrorage; _messagingClient = messagingClient; _log = log; }
static HttpTriggerFunction() { lineMessagingClient = new LineMessagingClient(System.Configuration.ConfigurationManager.AppSettings["ChannelAccessToken"]); var sp = ServicePointManager.FindServicePoint(new Uri("https://api.line.me")); sp.ConnectionLeaseTimeout = 60 * 1000; }
public LineBotApp(LineMessagingClient lineMessagingClient, jafleetContext context, ToolsContext toolsContext, IServiceScopeFactory serviceScopeFactory) { this.messagingClient = lineMessagingClient; _context = context; _tContext = toolsContext; _services = serviceScopeFactory; }
static LineComicsWebHookTrigger() { messagingClient = new LineMessagingClient(Environment.GetEnvironmentVariable("LINE_COMICS_ACCESS_TOKEN")); ServicePoint sp = ServicePointManager.FindServicePoint(new Uri("https://api.line.me")); sp.ConnectionLeaseTimeout = 60 * 1000; }
public static void Run([TimerTrigger("0 * * * * *")] TimerInfo myTimer, TraceWriter log) { //log.Info($"{DateTime.Now}:スタート"); try { // 商品検索 var janCode = ConfigurationManager.AppSettings["TargetGoods"].Split(',')[0]; var goodsName = ConfigurationManager.AppSettings["TargetGoods"].Split(',')[1]; Core.Crawler.Toysrus crawler = new Core.Crawler.Toysrus(); Core.Crawler.Toysrus.Result result = crawler.Run(janCode); if (result.Exist) { var message = $"【{goodsName}】が見つかりました。\n下記URLから購入を行ってください。\n{result.TargetUrl}"; LineMessagingClient lineMessagingClient = new LineMessagingClient(ConfigurationManager.AppSettings["AccessToken"]); lineMessagingClient.PushMessageAsync(ConfigurationManager.AppSettings["SendUserID"], message); } } catch (Exception ex) { log.Verbose($"{DateTime.Now}:{ex.ToString()}"); } finally { //log.Info($"{DateTime.Now}:エンド"); } }
public async Task PushLineMessage(ISendMessage replyMessage) { LineMessagingClient lineMessagingClient = new LineMessagingClient(System.Configuration.ConfigurationManager.AppSettings["ChannelAccessToken"]); var debugUserId = System.Configuration.ConfigurationManager.AppSettings["DebugUser"]; await lineMessagingClient.PushMessageAsync(debugUserId, new List <ISendMessage> { replyMessage }); }
static HttpTriggerFunction() { lineMessagingClient = new LineMessagingClient( Environment.GetEnvironmentVariable("JOALJaFzXSS1/Iw0lRElqFUMiBHUF4LhFisSOpo9WpfG4Ju5l+o+o5yTWeYVIqOhwPafmf63J283XV1uMahQlwgdfCxzlKipJygVt7h4z9Fbt0mq+eQivXcy4jj4oyvvH8a6cp39m8SO/3I9OyLmVgdB04t89/1O/w1cDnyilFU=")); var sp = ServicePointManager.FindServicePoint(new Uri("https://api.line.me")); sp.ConnectionLeaseTimeout = 60 * 1000; }
protected override async Task OnIntentRequestAsync(Intent intent, Session session, CancellationToken cancellationToken) { switch (intent.Name) { case "Clova.GuideIntent": Response .AddText("LINEに入力をした内容をしゃべります。準備はいいですか?") .KeepListening(); break; case "Clova.YesIntent": case "ReadyIntent": // 友だち追加チェック try { await LineMessagingClient.GetUserProfileAsync(session.User.UserId); } catch { Response.AddText("連携するLINEアカウントが友だち追加されていません。" + "Clovaアプリの本スキルのページから、連携するLINEアカウントを友だち追加してください。"); break; } await DurableClient.StartNewAsync(nameof(ClovaFunctions.WaitForLineInput), session.User.UserId); Response.AddText("LINEに入力をした内容をしゃべります。好きな内容をLINEから送ってね。"); // 無音無限ループに入る KeepClovaWaiting(); break; case "Clova.PauseIntent": // 無限ループ中の一時停止指示に対し、スキル終了をする await DurableClient.TerminateAsync(session.User.UserId, "intent"); Response.AddText("腹話術を終了します。"); break; case "Clova.NoIntent": case "Clova.CancelIntent": case "NotReadyIntent": // オーケストレーターが起動していないなら終了 var status = await DurableClient.GetStatusAsync(session.User.UserId); if (status?.RuntimeStatus == OrchestrationRuntimeStatus.ContinuedAsNew || status?.RuntimeStatus == OrchestrationRuntimeStatus.Pending || status?.RuntimeStatus == OrchestrationRuntimeStatus.Running) { Response.AddText("腹話術を終了します。"); } else { KeepClovaWaiting(); } break; } }
public LineBotController(IOptions <AppSettings> options) { appsettings = options.Value; lineMessagingClient = new LineMessagingClient(appsettings.LineBot.ChannelAccessToken); linePayClient = new LinePayClient( appsettings.LinePay.ChannelId, appsettings.LinePay.ChannelSecret, appsettings.LinePay.IsSandbox); }
public LINEClient(LINEConfig config) { this.config = config; messagingClient = new LineMessagingClient( config.ChannelAccessToken, config.Uri ); }
public LineBotController(IOptions <AppSettings> options) { appsettings = options.Value; #if DEBUG lineMessagingClient = new LineMessagingClient(appsettings.LineSettings.ChannelAccessToken, "http://localhost:8080"); #else lineMessagingClient = new LineMessagingClient(appsettings.LineSettings.ChannelAccessToken); #endif }
public LineMessagingClientTest() { userId1 = Environment.GetEnvironmentVariable("LINE_TEST_USER_ID_1"); userId2 = Environment.GetEnvironmentVariable("LINE_TEST_USER_ID_2"); roomId = Environment.GetEnvironmentVariable("LINE_TEST_ROOM_ID"); groupId = Environment.GetEnvironmentVariable("LINE_TEST_GROUP_ID"); var accessToken = Environment.GetEnvironmentVariable("LINE_ACCESS_TOKEN"); apiClient = new LineMessagingClient(accessToken); }
public LinePushController( IConfiguration configuration, ILogger <LinePushController> logger, IHostingEnvironment env) { this.configuration = configuration; this.logger = logger; this.env = env; lineMessagingClient = new LineMessagingClient(configuration["Line:ChannelAccessToken"]); }
public static async Task ProcessQueueMessage([QueueTrigger("line-bot-workitems")] string message, TextWriter log) { log.WriteLine(message); var data = JsonConvert.DeserializeObject <LineWebhookContent>(message); if (data?.Events != null) { foreach (var webhookEvent in data.Events) { log.WriteLine("event type: " + webhookEvent.Type); switch (webhookEvent.Type) { case WebhookRequestEventType.Message: if (webhookEvent.Message.Type == MessageType.Text) { log.WriteLine("text: " + webhookEvent.Message.Text); if (tokenResponse == null || tokenResponse.ExpiresIn < DateTime.Now.AddDays(-1)) { tokenResponse = await oAuthClient.GetAccessToken(); } var client = new LineMessagingClient(tokenResponse.AccessToken); var result = await new GitHubSearchApi(log).Search(webhookEvent.Message.Text); if (result == null || !result.Any()) { await client.PushMessage(webhookEvent.Source.UserId, "There is no content."); return; } foreach (var s in result.Where(x => !string.IsNullOrEmpty(x))) { if (s.Length > 1024) { await client.PushMessage(webhookEvent.Source.UserId, s.Substring(0, 1024)); } else { await client.PushMessage(webhookEvent.Source.UserId, s); } } } break; default: log.WriteLine("Not implemented event type: " + webhookEvent.Type); break; } } } }
static QueueTrigger() { httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(Aladin.Const.Domain); string accessToken = Environment.GetEnvironmentVariable("LINE_COMICS_ACCESS_TOKEN"); lineMessagingClient = new LineMessagingClient(accessToken); var sp = ServicePointManager.FindServicePoint(new Uri("https://api.line.me")); sp.ConnectionLeaseTimeout = 60 * 1000; }
public LineBotApp(LineMessagingClient lineMessagingClient, TableStorage <EventSourceState> tableStorage, BlobStorage blobStorage) { this.messagingClient = lineMessagingClient; this.sourceState = tableStorage; this.blobStorage = blobStorage; try { dlClient = new DirectLineClient(directLineSecret); } catch (Exception ex) { } }
public async Task <IActionResult> Post() { AccessToken accessToken = await _tokenManager.GetAccessTokenFromCache().ConfigureAwait(false); _messagingClient = new LineMessagingClient(accessToken.access_token); var events = await Request.GetWebhookEventsAsync(_botCredential.AppSecret); var app = new LineBotApp(_messagingClient); await app.RunAsync(events); return(Ok()); }
public override void Configure(IFunctionsHostBuilder builder) { var config = new ConfigurationBuilder() .AddJsonFile("local.settings.json", true) .AddEnvironmentVariables() .Build(); var settings = config.GetSection(nameof(LineBotSettings)).Get <LineBotSettings>(); builder.Services .AddSingleton(settings) .AddSingleton <ILineMessagingClient>(_ => LineMessagingClient.Create(settings.ChannelAccessToken)) .AddSingleton <IWebhookApplication, LineBotApp>(); }
public static LineMessagingClient GetInstance() { if (_client == null) { var config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build(); string channelAccessToken = config.GetSection("LineSettings")["ChannelAccessToken"]; #if DEBUG _client = new LineMessagingClient(channelAccessToken, "http://localhost:8080"); #else _client = new LineMessagingClient(channelAccessToken); #endif } return(_client); }
public static LineMessagingClient GetLineMessagingClient(string appSecret) { if (Instance == null) { lock (_sync) { if (Instance == null) { Instance = new LineMessagingClient(appSecret); } } } return(Instance); }