nimbasms_flutter
is a Flutter plugin for interacting with the Nimba SMS API. It allows you to send SMS, manage contacts, retrieve messages, and perform other SMS-related operations using the Nimba SMS service.
- Send SMS
- Retrieve all messages
- Retrieve a specific message by ID
- Retrieve account details
- Retrieve the list of contacts
- Create a new contact
- Retrieve the list of groups
- Create a verification
- Request verification
- iOS - Tested and working
- macOS - Tested and working
- Android - Tested and working
- Windows - Not tested yet
- Linux - Not tested yet
- Web - Tested and working
Add nimbasms_flutter
as a dependency in your pubspec.yaml
file:
dependencies:
flutter:
sdk: flutter
nimbasms_flutter: ^1.0.0
To enable network access for your application, you need to configure specific settings for iOS, macOS, and Android.
To enable network access for your application on iOS and macOS, you need to modify the entitlement files and add the necessary permissions:
Update Entitlements:
- Open the
ios/Runner/Runner.entitlements
file for iOS and themacos/Runner/DebugProfile.entitlements
andmacos/Runner/Release.entitlements
files for macOS. - Add the following lines to allow your application to make network requests:
<key>com.apple.security.network.client</key>
<true/>
For Android, you need to add the Internet permission to allow your application to access the network.
- Open the
android/app/src/main/AndroidManifest.xml
file. - Add the following line inside the
<manifest>
tag to grant Internet access:
<uses-permission android:name="android.permission.INTERNET" />
This permission ensures that your application has the necessary permissions to perform network operations on Android.
Once the platform-specific setup is complete, you can start using the nimbasms_flutter
plugin in your Flutter application.
First, import the nimbasms_flutter
package in your Dart code:
import 'package:nimbasms_flutter/nimbasms_flutter.dart';
Create an instance of the NimbaSMS
class with your service ID and secret:
void main() async {
final nimbaSMS = NimbaSMS(
serviceId: 'YOUR_SERVICE_ID',
secret: 'YOUR_SECRET',
);
try {
// Example: Send an SMS
Map<String, dynamic> smsResponse = await nimbaSMS.send(
senderName: 'Nimba SMS',
recipients: ['623XXXXXXX'],
message: 'Hello, Nimba SMS',
);
print('SMS sent successfully: $smsResponse');
} catch (e) {
print('Error: $e');
}
}
To send an SMS message using the Nimba SMS API:
final smsResponse = await nimbaSMS.send(
senderName: 'Nimba SMS', // The sender name
recipients: ['623XXXXXXX'], // List of phone numbers
message: 'Hello, this is a test message!', // The SMS body
);
You can retrieve all messages sent through your account:
final messages = await nimbaSMS.getMessages();
print(messages);
To get the details of a specific message by its ID:
final messageDetails = await nimbaSMS.getMessageById('MESSAGE_ID');
print(messageDetails);
To retrieve details about your Nimba SMS account:
final accountDetails = await nimbaSMS.getAccountDetails();
print(accountDetails);
You can retrieve or create contacts using the following methods:
-
Retrieve all contacts:
final contacts = await nimbaSMS.getContacts(); print(contacts);
-
Create a new contact:
final newContact = await nimbaSMS.createContact( name: 'Sona Camara', groups: ['Famille', 'Amis'], numero: '623XXXXXXX', ); print(newContact);
To retrieve the list of groups in your Nimba SMS account:
final groups = await nimbaSMS.getGroups();
print(groups);
To create a verification request for a specific phone number:
final verification = await nimbaSMS.createVerification(
to: '623XXXXXXX',
);
print(verification);
If an error occurs while using the plugin, it will throw an exception. You can catch errors like this:
try {
final messages = await nimbaSMS.getMessages();
} catch (e) {
print('Error: $e');
}
Contributions are welcome! If you have any suggestions, issues, or improvements, feel free to create an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.