Giter Club home page Giter Club logo

twilio_flutter's Introduction

Twilio Flutter

A Dart package for all platforms which helps developers with Twilio API services. This Dart Package can be integrated into any Flutter application to make use of Twilio API.

Features

  • Send SMS programmatically
  • Get all SMS related to a Twilio account
  • Get more info on each SMS sent from a Twilio account
  • Send WhatsApp messages programmatically
  • Send Scheduled SMS
  • Cancel Scheduled SMS
  • Send Scheduled WhatsApp message
  • Cancel Scheduled WhatsApp Message
  • Twilio verification supporting multiple channels
  • Send Messenger Texts

Getting Started

Check out our comprehensive Example provided with this plugin.

To use this package :

  • add the dependency to your pubspec.yaml file.
dependencies:
  flutter:
    sdk: flutter
  twilio_flutter:

How to use

Please find the following values from Twilio Console:

  • Account SID
  • Twilio Number
  • Auth Token
  • Messaging Service SID (Optional, required for features like scheduled messages)
  • Veridication service SID (Optional, required for Twilio verify feature)

Features and service list

Service Feature Feature info
TwilioFlutter Send SMS Send SMS to mobile number using Twilio number
TwilioFlutter Send WhatsApp message Send whatsApp message to any number from assigned Twilio number
TwilioFlutter Get SMS list Get all SMS from the account
TwilioFlutter Get SMS details Get all data related to a single SMS resource
TwilioMessagingService Send scheduled SMS Send SMS messages according to a time set, message will be sent from the service pool or send from custom number
TwilioMessagingService Cancel scheduled SMS Cancel scheduled SMS message
TwilioMessagingService Send scheduled whatsapp message Send WhatsApp message according to a time set, message will be sent from the service pool or send from custom number
TwilioMessagingService Cancel scheduled whatsapp message Cancel a scheduled whatsapp message
TwilioMessagingService Send SMS Send SMS message using messaging service, message will be sent from the service pool or send from custom number
TwilioMessagingService Send whatsapp message Send WhatsApp message, message will be sent from the service pool or send from custom number
TwilioMessenger Send FB messenger message Send FB messenger message

TwilioFlutter features

Create a new TwilioFlutter object and initialize with required values

final TwilioFlutter twilioFlutter = TwilioFlutter(
    accountSid: '', // replace with Account SID
    authToken: '', // replace with Auth Token
    twilioNumber: '' // replace with Twilio Number(With country code)
);

SMS

The following are the SMS related features in TwilioFlutter.

Send SMS

twilioFlutter.sendSMS() can be used to send SMS with required message body to any mobile number by providing the number and proper country code.

parameter type mandatory remarks
toNumber String Yes The number to which the message has to sent to, should be a mobile number with country code
messageBody String Yes The body of the SMS message
fromNumber String No A custom fromNumber other than the one configured with TwilioFlutter object.
  • Use sendSMS with the recipient number and message body using the default twilioNumber.
TwilioResponse response = await twilioFlutter.sendSMS(
toNumber : '',
messageBody : 'hello world');
  • Use sendSMS with the recipient number and message body using custom twilioNumber.
TwilioResponse response = await twilioFlutter.sendSMS(
toNumber : '',
messageBody : 'hello world',
fromNumber:''
);

WhatsApp

The following are the WhatsApp related features in TwilioFlutter.

Send WhatsApp Message

twilioFlutter.sendWhatsApp() can be used to send WhatsApp message with required message body to any mobile number by providing the number and proper country code.

TwilioResponse response = await twilioFlutter.sendWhatsApp(toNumber : '',// replace with Mobile Number(With country code)
messageBody : 'hello world');
parameter type mandatory remarks
toNumber String Yes The number to which the message has to sent to, should be a mobile number with country code
messageBody String Yes The body of the message
fromNumber String No A custom fromNumber other than the one configured with TwilioFlutter object. Should be mobile number with country code.

Twilio Verification

The following are the Twilio verify related features in TwilioFlutter.

Create verification service

Verification service has to be created in order to access all the features. This can be done either through the Twilio console or by using the following by providing a service name:

TwilioResponse response = await twilioFlutter.createVerificationService(serviceName:'service name');

This method returns TwilioResponse and metadata from TwilioResponse will have the verification service ID in the key: "sid". This sid should be used for the verification.

Send verification code

This method is used to send the verification code to the desired channel.

TwilioResponse response = await twilioFlutter.sendVerificationCode(verificationServiceId:'sid',
recipient: '',
verificationChannel: VerificationChannel.SMS
);

Currently supported channels are:

  • SMS
  • WHATSAPP
  • CALL

Recipient: can be mobile number, email etc depending on channel.

Verify code

To verify a code use the verify_code() method by passing the code input.

TwilioResponse response = await twilioFlutter.verifyCode(verificationServiceId:'sid',
recipient: '',
code: ''
);

This method returns TwilioResponse and metadata from TwilioResponse has a status key, if it is "approved" then the verification is successful.

Common

The following are the common services provided by TwilioFlutter.

View Messages List

The twilioFlutter.getSmsList() can be used to view all the SMS messages that was sent using the twilio account, an optional pageSize parameter can be passed which defaults to 20.

final TwilioResponse response = await twilioFlutter.getSmsList({String pageSize}); //pageSize defaults to 20

View Single Message

The twilioFlutter.getSMS() can be used to view the details of a single SMS message resource using the SID of the message. The SID can be found using the twilioFlutter.getSmsList().

final TwilioResponse response = await twilioFlutter.getSMS(String messageSID); //Use message sid from the individual messages.

Change Twilio Number

The twilioFlutter.changeDefaultTwilioNumber() can be used to update the default Twilio number that was used to initialize the TwilioFlutter object.

twilioFlutter.changeDefaultTwilioNumber(''); // To change the twilio number(With country code)

TwilioMessagingService features

Create a new TwilioMessagingService object and initialize with required values

final TwilioMessagingService twilioMessagingService = TwilioMessagingService(
    accountSid: '', // replace with Account SID
    authToken: '', // replace with Auth Token
    messagingServiceSid: '' // replace with messaging service sid from twilio console
);

SMS

The following are the SMS related features in TwilioMessagingService.

Send SMS using Messaging service

twilioMessagingService.sendSMS() can be used to send SMS with required message body to any mobile number by providing the number and proper country code. There is two ways to use the function:

  • Use sendSMS with the recipient number and message body using the default twilioNumber.
TwilioResponse response = await twilioMessagingService.sendSMS(
toNumber : '',// replace with Mobile Number(With country code)
messageBody : 'hello world');
  • Use sendSMS with the recipient number and message body using custom fromNumber.
TwilioResponse response = await twilioMessagingService.sendSMS(
toNumber : '',// replace with Mobile Number(With country code)
messageBody : 'hello world',
fromNumber:''// replace with Mobile Number(With country code)
);

Send Scheduled SMS Message

Scheduled messages can be sent using twilioMessagingService.sendScheduledSms() if the sendAt is at least 15 after the current time.

TwilioResponse response = await twilioMessagingService.sendScheduledSms(
toNumber : '',
messageBody : 'hello world',
sendAt:'2024-02-18T16:18:55Z'
// Datetime has to be in the same format
);

Cancel Scheduled SMS

Scheduled SMS can be cancelled using the messageSid with twilioMessagingService.cancelScheduledSms().

TwilioResponse response = await twilioMessagingService.cancelScheduledSms(messageSID:''// replace with message SID);

WhatsApp

The following are the WhatsApp related features in TwilioMessagingService.

Send WhatsApp Message

twilioMessagingService.sendWhatsAppMessage() can be used to send WhatsApp message with required message body to any mobile number by providing the number and proper country code.

TwilioResponse response = await twilioMessagingService.sendWhatsAppMessage(toNumber : '',// replace with Mobile Number(With country code)
messageBody : 'hello world');

Send Scheduled WhatsApp Message

Scheduled messages can be sent using twilioMessagingService.sendScheduledWhatsAppMessage() if the sendAt is at least 15 after the current time.

TwilioResponse response = await twilioMessagingService.sendScheduledWhatsAppMessage(
toNumber : '',
messageBody : 'hello world',
sendAt:'2024-02-18T16:18:55Z'
// Datetime has to be in the same format
);

Cancel Scheduled WhatsApp Message

Scheduled whatsapp messages can be cancelled using the messageSid with twilioMessagingService.cancelScheduledWhatsAppMessage().

TwilioResponse response = await twilioMessagingService.cancelScheduledWhatsAppMessage(messageSID:''// replace with message SID
);

TwilioMessenger features (Experimental)

Create a new TwilioMessenger object and initialize with required values

final TwilioMessenger twilioMessenger = TwilioMessenger(
    accountSid: '', // replace with Account SID
    authToken: '', // replace with Auth Token
    messengerId: '' // replace with FB page ID
);

Send Messenger text

Send Messenger text message using the send_messenger() method.

TwilioResponse response = await twilioMessenger.sendMessenger(recipient:'',
messageBody: ''
);

TwilioResponse

All the function calls from all the services will return a TwilioResponse Object.

TwilioResponse wraps the response of all the APIs. The fields in TwilioResponse:

  • responseCode: give the response code of the requests. Possible values: 200,400 etc.
  • responseState: shows if the request fails or completes properly. Possible values: ResponseState.SUCCESS or ResponseState.FAILED
  • errorData : Holds the ErrorData object in case of any failures/exceptions.
  • metadata : Holds all the info from the response of the API as json.

ErrorData object has the details about the errors. The fields are:

  • code
  • status
  • message
  • more_info

Future Features

  • Cancel Scheduled Messages
  • Send message through Facebook Messenger
  • Twilio verification
  • Email Sending Support
  • Update a Message resource
  • Delete a Message resource
  • Alphanumeric Sender IDs in Messaging Services
  • More Support for Messaging Service

Supported Platforms

  • Android
  • iOS
  • Web
  • MacOs
  • Windows
  • Linux

Useful articles

Issues

Please file any issues, bugs or feature requests as an issue on our GitHub page.

Want to contribute

If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our contribution guide and send us your pull request.

Author

This Twilio Flutter plugin for Flutter is developed by Adarsh Balachandran.

twilio_flutter's People

Contributors

adarshbalu avatar dokotela avatar sebastianklaiber avatar thameemkj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

twilio_flutter's Issues

whatsapp message error

I can't send whatsapp message Twilio could not find a Channel with the From address Error 63007

chat user etc

This lib provide sendsms, whatsappsms etc, when will it gives "chat with other user", "chat with group", video calling facility

Help with Documentation

Help with documentation of the package is very much appreciated. Comment if interested in helping me out.

Suggestion regarding usage of 'from number'

You are taking 'from number' from the constructor itself (I mean during class instantiation), and sendSMS, sendWhatsApp methods are called with parameters 'to' and 'message content'.
Here the problem is that, if the user has multiple twilio numbers, and wants to send sms and whats app message from different numbers, it will not be possible.
My suggestion is that, take a "from number" during instantiation (as it is now), and provide an optional parameter in the methods to give "from number". And if the optional parameter is null use the number given during instantiation or else use the number in the optional parameter.

messagingServiceSid doesnt work

Hi,
Beautiful work ! I can send SMS, it's great !! Thanks.
Although, use of messagingServiceSid doesn't seem to work. I received a SMS from the phone number (short) but not from the messagingService I configured in my Twilio console :-/

Normally, twilioNumber is not mandatory if we use messagingServiceSid :

curl 'https://api.twilio.com/2010-04-01/Accounts/[MyAccountSID]/Messages.json' -X POST
--data-urlencode 'To=+33xxxxxxx'
--data-urlencode 'MessagingServiceSid=[MyMessagingServiceId]'
--data-urlencode 'Body=test'
-u [MyAccountSID]:[AuthToken]

Thanks for your help
JF

Phone verification

Hello, does your package support twilio phone verification in flutter ?

Incorrect request body SMS verification

Hi,

I just tried out the SMS verification, and it seems like there is a small bug in the Implementation. The Fix is quite easy but needs a change in the dart version constraints.

The channel contains the name of the enum.
To=...&Channel=verificationchannel.sms

If it is ok for you, I would create a PR, increase the constraints to dart 2.15.0 and use name instead of the toString(). In TwilioVerifyServiceImpl line 47.

[Feature Request] Send emails

Hi, Thanks for the great package. Twilio uses Sendgrid to send emails. It would be great if you add that as well.

I am trying to send sms in trial version but facing Unhandled Exception: Exception

I am using this plugin for sending sms in trial version. Whenever I try to send sms to different number other than I added in console, I got an exception which I am unable to handle, I tried wrapping with try, catch block of My code when sending sms so i can catch the exception but failed.
Whenever I call twilioFlutter.sendSMS method I got an exception and my app crashes.
Here is my Code:
try {
twilioFlutter.sendSMS(
toNumber: phoneNumber,
messageBody: 'Irfan Sadiq is sending message and your code is $otp');
} catch (e) {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('Something went wrong')));
}
Any help, fixes will be highly appreciated.
Thanks

Check response after sending SMS

Am trying to check a response either failed or success but It's only displaying in the console. but I can't display it on the UI.

twilioFlutter.sendSMS(toNumber: '+2349057463831', messageBody: AppString.smsBody, ).then((value){
print('Value $value'); //Doesnt display
}).catchError((error){
print('Catch Error ${error.toString()}'); //Only display "Exception"
});

Return status response

I suggest you add a status response to check if the operation went successfully or not.

Incompatible issue

Could you please release another version that use http ^0.13.0 am having trouble to get the package duo to incompatibility issue with another package

Null Safety

please can you upgrade your project to support null safety

flutter SocketException

Exception has occurred.
SocketException (SocketException: Failed host lookup: 'api.twilio.com' (OS Error: No address associated with hostname, errno = 7))

Whatsapp send image/QR/HTML. Possible?

Am currently using trial version of Twilio. The plain string goes across successfully. But am having trouble finding documentation supporting html/images.

May I know if this is in anyway possible? If so, could you direct me to the solution?

I am fully aware that this is more of a "discussion" than an issue, but it doesn't seem that discussion tab is open, and I figured it'd be better to directly go to the source. Thanks in advance.

I can't send whatsapp messages.

I can't send whatsapp messages. The error is "Twilio could not find a Channel with the specified From address
"with error code 63007

Alphanumeric Sender IDs

Hi,
Thanks alot for this package. I'm currently making use of it. However I would want to implement the "Alphanumeric Sender IDs" functionality where I will love to change my twilo-account-phone-number to my company name on sending to my users. Is that possible with this package??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.