> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/examples/echo-bot/dart-flutter.md).

# Dart / Flutter

```dart
import 'package:dnotifier/dnotifier.dart';

const botId = 'echo-bot';

String extractSenderId(String prefixedSender, String appId) {
  final prefix = '${appId}_';
  if (prefixedSender.startsWith(prefix)) {
    return prefixedSender.substring(prefix.length);
  }
  return prefixedSender;
}

Future<void> main() async {
  final appId = const String.fromEnvironment('DNOTIFIER_APP_ID');

  final notifier = DNotifier(
    appId: appId,
    secret: const String.fromEnvironment('DNOTIFIER_SECRET'),
    transport: 'ws',
    userId: botId,
    onConnected: () => print('Echo bot ready'),
    onMessage: (msg) async {
      final body = msg.payload.toJSON();
      if (body is! Map || body['type'] != 'text') return;
      final text = body['text']?.toString();
      if (text == null || text.isEmpty) return;

      final senderUserId = extractSenderId(msg.metadata.sender, appId);

      await notifier.send(
        senderId: botId,
        receiverId: senderUserId,
        data: {'type': 'text', 'text': 'Echo: $text'},
      );
      print('Echoed to $senderUserId: $text');
    },
    onDisconnected: ({code, reason}) => print('Disconnected: $reason'),
  );

  await notifier.connect();
  await Future.delayed(const Duration(hours: 1));
}
```

## Test

Send from another client to `echo-bot` and verify the `Echo:` prefix in the reply.
