Library of the LINE Messaging API for Dart

IMPORTANT: This is not an official SDK by LINE


We make it easy to developers to code their bots with Dart! A few steps to create a parser and bot to handle requests and reply messages. The library is based on the official LINE Messaging API Document and inspired by the official SDK: line-bot-sdk-python

Implemented methods, events and messages

  • x Support parser and test cases for webhook event objects
  • x Validation with signature from x-line-signature
  • x Reply message with TextMessage
  • x Get Bot Info
  • x Get user profile and followers


import 'dart:convert';
import 'dart:io';

import 'package:line_bot/line_bot.dart';

Future main() async {
  var envVars = Platform.environment;
  var lineChannelSecret = envVars['LINE_CHANNEL_SECRET'];
  var lineChannelAccessToken = envVars['LINE_CHANNEL_ACCESS_TOKEN'];
  var lineBotApi = LineBotApi(lineChannelAccessToken);
  var webhookParser = WebhookParser(lineChannelSecret);
  var server = await HttpServer.bind(
  await for (var request in server) {
    if (request.method == 'POST' && request.uri.path == '/callback') {
      handleRequest(request, webhookParser, lineBotApi);
    } else {

void handleRequest(HttpRequest request, WebhookParser webhookParser,
    LineBotApi lineBotApi) async {
  var message;
  var response = request.response;
  var content = await utf8.decoder.bind(request).join();
  try {
    message = webhookParser.parser(
        content.toString(), request.headers['x-line-signature'][0]);
  } on InvalidSignatureError {
    await response
      ..statusCode = HttpStatus.badRequest
  if ( {
    var messages = [
      Message(type: 'text', text:[0].message.text)
    await lineBotApi.replyMessage([0].replyToken, messages);
    ..statusCode = HttpStatus.ok
    ..write('Request Accepted.')

void handleUnSupportedRequest(HttpRequest request) {
  var response = request.response;
    ..statusCode = HttpStatus.methodNotAllowed
    ..write('Unsupported request: ${request.method}.')

Features and bugs

Please file feature requests and bugs at the issue tracker.