ym_flutter_integration 0.0.1
ym_flutter_integration: ^0.0.1 copied to clipboard
A Flutter plugin for integrating Yellow Messenger chatbots in your flutter application.
ym_flutter_integration #

A Flutter plugin for integrating Yellow Messenger chatbots in your flutter application
Overview #
Gives a widget to show chatbot on your mobile application, and listen to the events emitted from the chatbot
Usage #
To use this plugin, add ym_flutter_integration as a dependency in your pubspec.yaml file.
Getting started #
Initialise the YmBotSdk and set the initial configurations
import 'package:flutter/material.dart';
import 'package:ym_bot_sdk/models/botEvents.dart';
import 'package:ym_bot_sdk/ym_bot_sdk.dart';
class _BotPageState extends State<BotPage> {
YmBotSdk ymBotSdk;
String botId = "<Your botId goes here>";
@override
void initState() {
super.initState();
ymBotSdk = YmBotSdk();
ymBotSdk.setConfig(
context: context,
botId: botId,
enableHistory: false,
enableSpeech: false,
enableCloseButton: true);
}
}
Call getBotWidget() method on the ymBotSdk object to get the chatbot widget
ymBotSdk.getBotWidget(
botEventListener: (BotEvent botEvent) {
switch (botEvent.code) {
case "event1":
ymBotSdk.closeBot();
print("code is ${botEvent.code}, data");
print("is ${botEvent.data}");
break;
default:
print("No data");
}
},
),
Methods #
setConfig(...): To set initial configurations to the chatbot ( Config should be added befioring callign thegetBotWidget(...))getBotWidget(...): To get the chatbot widgetcloseBot(...): close the chatbotaddPayload(...): add the payload to the chatbot ( payload is sent to chatbot once theupdatePayloadis called)updatePayload(...): to send the added payload to the chatbotclearPayload(...): To delete all exsting a nd added payloads
SetConfig(...) #
Flags
enableHistory: to send the added payload to the chatbot
Example:
String botId = "<Your bot id goes here>";
BuildContext context = <Widget context>;
bool enableHistory = false;
bool enableSpeech = false;
bool enableCloseButton = false;
ymBotSdk.setConfig
( botId,
context,
enableHistory,
enableSpeech,
enableCloseButton);
getBotWidget(...) #
Call getBotWidget() method on the ymBotSdk object to get the chatbot widget
Example:
ymBotSdk.getBotWidget(
botEventListener: (BotEvent botEvent) {
switch (botEvent.code) {
case "event1":
ymBotSdk.closeBot();
print("code is ${botEvent.code}, data");
print("is ${botEvent.data}");
break;
default:
print("No data");
}
},
),