Skip to content

ed555009/line-notify-api-client

Repository files navigation

Line.Notify.Api.Client

GitHub Build Status Nuget

Coverage Quality Gate Status Reliability Rating Security Rating Vulnerabilities

Description

This is a .NET6 library for interacting with the LINE Notify Api.

Quick start

Installation

dotnet add package Line.Notify.Api.Client

Appsettings.json

{
	"Line": {
		"Notify": {
			"BaseUrl": "https://notify-api.line.me",
			"AuthToken": "YOUR_LINE_AUTH_TOKEN"
		}
	}
}

Add services

using Line.Notify.Api.Client.Extensions;

ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
	// this injects as SINGLETON
	services.AddLineNotifyApiServices(configuration);

	// you can also inject as SCOPED or TRANSIENT by specifying the ServiceLifetime
	services.AddLineNotifyApiServices(configuration, ServiceLifetime.Scoped);
}

Using services

using Line.Notify.Api.Client.Interfaces;
using Line.Notify.Api.Client.Services;
using Line.Notify.Api.Client.Models.Requests;

public class MyProcess
{
	private readonly INotifyService _notifyService;

	public MyProcess(INotifyService notifyService) =>
		_notifyService = notifyService;

	public async Task NotifyAsync()
	{
		// use the default token from appsettings.json
		var result = await _notifyService.NotifyAsync(new MessageModel
		{
			Message = "Test message"
		});

		// or pass in another token so you can send notification to multiple LINE account at the same time
		var dynamicTokenResult = await _notifyService.NotifyAsync(
			new MessageModel
			{
				Message = "Test message"
			},
			"MyAuthToken");
	}
}

Reference

About

A nuget package for LINE Notify Api client using .NET6

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages