botnoi_dev_platform 0.0.11
botnoi_dev_platform: ^0.0.11 copied to clipboard
A flutter package for creating and training chatbot on botnoi.ai using botnoi developer platform api.
Botnoi Dev Platform is a programatical alternative to the visual chatbot builder provided by https://botnoi.ai. It can be used to build and train chatbots for various platforms such as Facebook Messenger and LINE.
This official library provides a Dart implementation of Botnoi Dev Platform's API in order to simplify the process of building chatbots. It also provides various data types related to chatbots such as 'BotIntents', 'BotObjects' and lots of helper functions to work with them.
This suits best for developers who want to build chatbots programmatically or to automate the process of chatbot training when an action is performed by the applications' users.
Getting started #
first, add the package to your pubspec.yaml file
dependencies:
botnoi_dev_platform: ^latest_version
then, import the package
import 'package:botnoi_dev_platform/botnoi_dev_platform.dart';
note: you have to have an API key to use this package. You can get one from https://botnoi.ai
Usage #
- First, you have to initialize the BotnoiChatbot server with your API key
BotnoiChatbot.initializeClient(key: 'your_api_key');
- Then, you can create a BotnoiChatbot instance and create a new bot or find an existing one
BotnoiChatbot server = BotnoiChatbot();
// create a new Bot instance
Bot newBot = Bot(
botName: "newBot",
sex: "male",
age: 20,
owner: "new_owner",
botAvatar: "https://example.com/avatar.png",
businessType: ["education"],
);
// add the new Bot instance to the server
await server.createBot(bot: newBot);
- You can create an intent in side of that server by creating a new BotIntent instance and add it to the bot
// create a new BotIntent instance
BotIntent newIntent = BotIntent(
name: "newIntent",
);
// get the bot back from the server
// this is required because the bot's id is generated by the server
newBot = (await server.findBotWithName("newBot"))!;
// add the new BotIntent instance to the bot
await newBot.opt.createIntent(intent: newIntent);
note: Alternatively, you can use newBot.reload() to keep the bot instance up to date with the server
- You can train the intent by adding some keywords(inputs) and messages(outputs) to it
// get the intent back from the server
// this is required because the intent's id is generated by the server
newIntent = (await newBot.opt.findIntentWithName("newIntent"))!;
// train the intent
await newIntent.opt!.trainKeyword(keyword: "Hello");
await newIntent.opt!.trainMessage(message: "Hello! how are you?");
note: Alternatively, you can use newIntent.reload() to keep the intent instance up to date with the server
- Botnoi Dev Platform is designed not to break the application when errors occur. Instead, it will stream the error messages. To handle these errors, you can set the callback function to be called when an error occurs
BotnoiChatbot.setErrorCallback((error) {
// handle the error here
print(error);
});