Wannatalk Official Flutter plugin.
Edit the pubspec.yaml
file in your app directory to define the Wannatalk SDK dependency:
dependencies:
wannatalkcore: ^0.0.25
-
Request WTService-Info.plist from wannatalk.ai and drag it into your application. When prompted, select "Copy items if needed" and continue.
-
Add below keys in your application's Info.plist
<key>NSPhotoLibraryUsageDescription</key> <string>To save in-chat photos and videos</string> <key>NSContactsUsageDescription</key> <string>To locate friends already on the Wannatalk network</string> <key>NSCameraUsageDescription</key> <string>To take photos and videos to send to friends in-chat</string> <key>NSLocationWhenInUseUsageDescription</key> <string>To display it in map</string> <key>NSMicrophoneUsageDescription</key> <string>To record live photos and movies</string>
-
Add this line to your application pod file
pod 'WTExternalSDK', :git =>'https://github.com/edzehoo/WannatalkAPI-iOS.git', :tag => '1.8.1'
-
That's it! Run the app
- Copy trim.sh file into your project folder.
- Create Run Script Phase in Build Phases of your application target.
- Paste
"$SRCROOT/trim.sh"
inside the body of Run Script Phase. - Enable
Run script only when installing
andShow environment variables in build log
.
- Request wannatalk-services.json from wannatalk.ai and drag it into your application
assets
directory
android {
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
...
}
-
Set colorPrimary, colorPrimaryDark and colorAccent attributes in app's color.xml (src/main/res/values/colors.xml)
-
Add
maven { url 'https://jitpack.io' }
in your project build.gradleallprojects { repositories { ... maven { url 'https://jitpack.io' } ... } }
-
That's it! Run the app
import 'package:wannatalkcore/wannatalkcore.dart';
Wannatalkcore.login(onCompletion: (WTResult result) {
if (result.success) {
}
});
Wannatalkcore.silentLogin("<user_identifier>", { displayname: "name", key1: "Value1", key2: "Value2"}, onCompletion: (WTResult result) {
if (result.success) {
}
});
bool loggedIn = await Wannatalkcore.isUserLoggedIn;
Wannatalkcore.logout(onCompletion: (WTResult result) {
});
This callback will be triggered to notify events:
- kWTEventTypeLogin: This event will be triggered when user login into wannatalk account.
evenResponse.success
indicates whether login successful or not. If fails, check error information ateventResponse.error
. - kWTEventTypeLogout: This event will be triggered when user loggout from wannatalk account.
evenResponse.success
indicates whether logout successful or not. If fails, check error information ateventResponse.error
. - kWTEventTypeProduct: This event will be triggered when user click on product image in chat page.
evenResponse.result
contains productID and storeID of the respective product image message.
Wannatalkcore.setMethodCallHandler(onReceivedEvent:(WTEventResponse eventResponse) {
switch (eventResponse.eventType) {
case WTEventResponse.kWTEventTypeProduct: {
var result = eventResponse.result;
if (result.success) {
if (result.productID != null && result.storeID != null) {
print("ProductID: " + result.productID!);
print("StoreID: " + result.storeID!);
}
}
else {
// Error
print(result.error);
}
break;
}
}
});
String receiverUserIdentifier = "+60199299399499"; // Receiver mobile number with calling code
String message = "Hi"; // Message you want to send to user
Wannatalkcore.sendTextMessage(receiverUserIdentifier, message, onCompletion: (WTResult result) {
if (result.success) {
}
});
String receiverUserIdentifier = "+60199299399499"; // Receiver mobile number with calling code
String productID = "<productID>"; // Product identifier
String productName = "<productName>"; // Optional // Product name
String productPrice = "<productPrice>"; // Optional // Product price
String productImageUrl = "https://upload.wikimedia.org/wikipedia/commons/a/ab/Apple-logo.png"; // Product image url
String caption = "Can share details about this product?"; // caption will be sent to receiver along with image
String storeID = "<storeID>"; // Store/Shop identifier
WTChatInput chatInput = WTChatInput.Product(productID, productName,
productPrice, productImageUrl,
caption, storeID);
Wannatalkcore.sendProductImage(receiverUserIdentifier, chatInput, onCompletion: (WTResult result) {
if (result.success) {
}
});
String orgID = "your_organization_id";
String channelID = "your_chat_channel_id";
String message = "Hi"; // This message will be sent upon opening chat
String ticketName = "alpha"; // Ticket name
bool closeOldTickets = false; // If true, closes all active tickets, else opens existing active ticket
Wannatalkcore.contactOrganization(orgID, channelID, ticketName, closeOldTickets, message, onCompletion: (WTResult result) {
if (result.success) {
}
});
Wannatalkcore.loadOrganizationProfile(autoOpenChat, onCompletion: (WTResult result){
});
Wannatalkcore.loadChats(onCompletion: (WTResult result) {
});
Wannatalkcore.loadUsers(onCompletion: (WTResult result) {
});
WannatalkConfig.showGuideButton(true); // default = true
WannatalkConfig.allowSendAudioMessage(false); // default = true
WannatalkConfig.allowAddParticipants(false); // default = true
WannatalkConfig.allowRemoveParticipants(false); // default = false
WannatalkConfig.showWelcomeMessage(false); // default = false
WannatalkConfig.showProfileInfoPage(false); // default = true
Chat ticket will create automatically when auto tickets is enabled, otherwise default ticket creation page will popup
WannatalkConfig.enableAutoTickets(true); // default = false
WannatalkConfig.showExitButton(true); // default = false
WannatalkConfig.showChatParticipants(false); // default = true
WannatalkConfig.enableChatProfile(false); // default = true
WannatalkConfig.allowModifyChatProfile(false); // default = true
Chat session will end if user is inactive for timeout interval duration. If timeout interval is 0, chat session will not end automatically. The default timout interval is 1800 seconds (30 minutes).
double timeoutInterval = 1800; // Default Value: 1800 seconds ~ 30 minutes
WannatalkConfig.setInactiveChatTimeoutInterval(timeoutInterval);