botnoi_dev_platform 1.2.17 copy "botnoi_dev_platform: ^1.2.17" to clipboard
botnoi_dev_platform: ^1.2.17 copied to clipboard

A flutter package for creating and training chatbot on botnoi.ai using botnoi developer platform api.

example/lib/example.dart

import 'package:botnoi_dev_platform/botnoi_dev_platform.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatefulWidget {
  const MainApp({super.key});

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  @override
  void initState() {
    BotnoiChatbot.initializeClient(key: "your-key-here");
    BotnoiChatbot.initializeCollector();
    super.initState();
  }

  BotnoiChatbot server = BotnoiChatbot.serverInstance;

  Bot? demoBot;
  BotIntent? demoIntent;
  BotObject? demoObject;

  TextEditingController botNameController = TextEditingController();
  TextEditingController intentNameController = TextEditingController();
  TextEditingController userMessageController = TextEditingController();
  TextEditingController botResponseController = TextEditingController();
  TextEditingController objectNameController = TextEditingController();
  TextEditingController apiNameController = TextEditingController();
  TextEditingController apiUrlController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text("Botnoi Dev Platform Demo"),
        ),
        body: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.fromLTRB(20, 20, 20, 0),
            child: Column(
              children: [
                Container(
                  width: double.infinity,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(10),
                    border: Border.all(color: Colors.blue, width: 2),
                  ),
                  child: Padding(
                    padding: const EdgeInsets.all(20),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        const Text(
                          "You are working on:",
                          style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
                        ),
                        const SizedBox(height: 20),
                        Text(
                          "bot :  ${demoBot?.botName ?? "none"}",
                          style: const TextStyle(fontSize: 22),
                        ),
                        const SizedBox(height: 10),
                        Text(
                          "intent :  ${demoIntent?.name ?? "none"}",
                          style: const TextStyle(fontSize: 22),
                        ),
                        const SizedBox(height: 10),
                        Text(
                          "object :  ${demoObject?.objectName ?? "none"}",
                          style: const TextStyle(fontSize: 22),
                        ),
                      ],
                    ),
                  ),
                ),
                const SizedBox(
                  height: 30,
                  child: Divider(
                    thickness: 1,
                  ),
                ),
                SizedBox(
                  width: 300,
                  child: TextField(
                    controller: botNameController,
                    decoration: const InputDecoration(
                      hintText: "Bot name",
                      border: OutlineInputBorder(),
                    ),
                  ),
                ),
                TextButton(
                  onPressed: () async {
                    await server.createBot(
                      bot: Bot(
                        botName: botNameController.text,
                        sex: "male",
                        age: 20,
                        botAvatar: "",
                        businessType: "Education",
                      ),
                    );
                    demoBot = await server.findBotWithName(botNameController.text);
                    setState(() {});
                  },
                  child: const Text(
                    "Create Bot",
                    style: TextStyle(fontSize: 20),
                  ),
                ),
                const SizedBox(
                  height: 30,
                  child: Divider(
                    thickness: 1,
                  ),
                ),
                SizedBox(
                  width: 300,
                  child: TextField(
                    controller: intentNameController,
                    decoration: const InputDecoration(
                      hintText: "Intent name",
                      border: OutlineInputBorder(),
                    ),
                  ),
                ),
                TextButton(
                  onPressed: () async {
                    if (demoBot != null) {
                      demoIntent = BotIntent(name: intentNameController.text);
                      await demoBot!.opt.createIntent(intent: demoIntent!);
                      await demoIntent!.reload();
                      setState(() {});
                    }
                  },
                  child: const Text(
                    "Create intent",
                    style: TextStyle(fontSize: 20),
                  ),
                ),
                const SizedBox(
                  height: 30,
                  child: Divider(
                    thickness: 1,
                  ),
                ),
                SizedBox(
                  width: 300,
                  child: TextField(
                    controller: userMessageController,
                    decoration: const InputDecoration(
                      hintText: "User's message",
                      border: OutlineInputBorder(),
                    ),
                  ),
                ),
                const SizedBox(height: 10),
                SizedBox(
                  width: 300,
                  child: TextField(
                    controller: botResponseController,
                    decoration: const InputDecoration(
                      hintText: "Bot's response",
                      border: OutlineInputBorder(),
                    ),
                  ),
                ),
                TextButton(
                  onPressed: () async {
                    if (demoIntent != null) {
                      await demoIntent!.opt!.trainKeyword(keyword: BotIntentKeyword(keyword: userMessageController.text));
                      await demoIntent!.opt!.trainReaction(reaction: BotIntentReaction(actions: [botResponseController.text]));
                      setState(() {});
                    }
                  },
                  child: const Text(
                    "Train Intent",
                    style: TextStyle(fontSize: 20),
                  ),
                ),
                const SizedBox(
                  height: 30,
                  child: Divider(
                    thickness: 1,
                  ),
                ),
                SizedBox(
                  width: 300,
                  child: TextField(
                    controller: apiNameController,
                    decoration: const InputDecoration(
                      hintText: "API name",
                      border: OutlineInputBorder(),
                    ),
                  ),
                ),
                const SizedBox(height: 10),
                SizedBox(
                  width: 300,
                  child: TextField(
                    controller: apiUrlController,
                    decoration: const InputDecoration(
                      hintText: "API url",
                      border: OutlineInputBorder(),
                    ),
                  ),
                ),
                TextButton(
                  onPressed: () async {
                    if (demoBot != null) {
                      demoObject = BotObject(
                        objectName: apiNameController.text,
                        objects: [
                          BotApiObject(
                            url: apiUrlController.text,
                            method: "get",
                            header: {"Content-Type": "application/json"},
                            body: "",
                          )
                        ],
                      );
                      await demoBot!.opt.createObject(object: demoObject!);
                      await demoObject!.reload();
                      BotnoiChatbot.collector.reloadIntent("myIntent");
                      BotnoiChatbot.collector.trashIntent("myIntent");
                      setState(() {});
                    }
                  },
                  child: const Text(
                    "Create API object",
                    style: TextStyle(fontSize: 20),
                  ),
                ),
                const SizedBox(
                  height: 30,
                  child: Divider(
                    thickness: 1,
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
2
likes
135
points
47
downloads

Publisher

unverified uploader

Weekly Downloads

A flutter package for creating and training chatbot on botnoi.ai using botnoi developer platform api.

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, get_it, http, universal_html, url_launcher

More

Packages that depend on botnoi_dev_platform