WhatsApp API package for flutter, to send message and product information.
- WhatsApp Business Configuration
- π¬ Short link
- π¬ Send template
- π¬ Send text message
- π¬ Send media files
- π¬ Send location details
- π¬ Send media by link
- π¬ Send reaction on message
- π¬ Send reply on message
- π¬ Send reply with media
- π¬ Send reply with media url
- π Register a number
- π Deregister a number
- π Get Shared WhatsApp Business Account Id
- π Get Shared WhatsApp Business Account List
- π Send button options
- π Upload media files
- π Delete media files
- π Retrive media url
- π Update Business profile
- π Two step verification code
You must have WhatsApp apps in facebook developer, to use this package, please follow this Guidelines.
WhatsApp whatsapp = WhatsApp();
Configure accessToken
and fromNumberId
.
whatsapp.setup(
accessToken: "your_access_token_here",
fromNumberId: 10000000000000
);
π¬ Generate the short link of the WhatsApp.
to
- the phone number with country code but without the plus (+) sign.message
- the message to be sent.compress
- passtrue
to compress the link.
whatsapp.short(
to: 910000000000,
message: "Hey",
compress: true
);
//return : https://wa.me/910000000000?text=Hy
π¬ Send the template to the client.
to
- the phone number with country code but without the plus (+) sign.templateName
- the template name.
whatsapp.messagesTemplate(
to: 910000000000,
templateName: "hello_world"
);
π¬ Send the text message to the client.
to
- the phone number with country code but without the plus (+) sign.message
- the message to be sent.previewUrl
- is used to preview the URL in the chat window.
whatsapp.messagesTemplate(
to: 910000000000,
message: "Hey, Flutter, follow me on https://example.com",
previewUrl: true
);
π¬ Send the media files to the client.
to
- the phone number with country code but without the plus (+) sign.mediaType
- the type of media such as image, document, audio, image, or videomediaId
- Use this edge to retrieve and delete media.
whatsapp.messagesMedia(
to: 910000000000,
mediaType: "image",
mediaId: "f043afd0-f0ae-4b9c-ab3d-696fb4c8cd68"
);
π¬ Send the location to the client.
to
- the phone number with country code but without the plus (+) sign.longitude
- the longitude of the location.latitude
- the latitude of the location.name
- the name of the location.address
- the full address of the location.
whatsapp.messagesLocation(
to: 910000000000,
longitude: "26.4866491",
latitude: "74.5288578",
name: "Pushkar",
address: "Rajasthan, India"
);
π¬ Send the location to the client.
to
- the phone number with country code but without the plus (+) sign.mediaType
- the type of media such as image, document, audio, image, or videomediaLink
- the media to be sent.caption
- the caption of media
whatsapp.messagesMediaByLink(
to: 910000000000,
mediaType:"video",
mediaLink: "https://example.com/flutter.mp4",
caption:"My Flutter Video"
);
π¬ Send the location to the client.
to
- the phone number with country code but without the plus (+) sign.messageId
- the message id.emoji
- the emoji to be sent.
whatsapp.messagesReaction(
to: 910000000000,
messageId: "wamid.xxxxxxxxxxxxxxxxxx==",
emoji: "π"
);
π¬ Send the location to the client.
to
- the phone number with country code but without the plus (+) sign.messageId
- the message id.message
- the message to be sent.previewUrl
- used to preview the URL in the chat window.
whatsapp.messagesReply(
to: 910000000000,
messageId: "wamid.xxxxxxxxxxxxxxxxxx==",
message: "Hey, Flutter!",
previewUrl: true
);
π¬ Reply to a media by ID
to
- the phone number with country code but without the plus (+) sign.messageId
- the message id.mediaType
- type of media such as image, document, audio or videomediaId
- id of media to be replay.
whatsapp.messagesReplyMedia(
to: 910000000000,
messageId: "wamid.xxxxxxxxxxxxxxxxxx==",
mediaType: "image",
mediaId: "1000000000000000"
);
π¬ Reply to a media by URL
to
- the phone number with country code but without the plus (+) sign.messageId
- the message id.mediaType
- type of media such as image, document, audio or videomediaLink
- link of media to be replay.caption
- caption of media to be replay.
whatsapp.messagesReplyMediaUrl(
to: 910000000000,
messageId: "wamid.xxxxxxxxxxxxxxxxxx==",
mediaType: "video",
mediaLink: "http://example.com/video.mp4",
caption: "My Flutter Video"
);
π Register a phone number
pin
is 6-digit pin for Register number.
whatsapp.registerNumber(
pin:"123456"
);
π Deregister a phone number
pin
is 6-digit pin for deregister number.
whatsapp.deregisterNumber(
pin:"123456"
);
π Get Shared WhatsApp Business Account Id
inputToken
- token generated after embedding the signup flow
whatsapp.getWhatsAppBusinessAccounts(
inputToken:"EAAFl...."
);
π Get Shared WhatsApp Business Account List
accountId
- Business manager account Id
whatsapp.getWhatsAppBusinessAccountsList(
accountId: 805021500648488
);
π Send message with action buttons for choice
to
- the phone number with country code but without the plus (+) sign.bodyText
-the main body text of messagebuttons
- list of action buttons with id and text
whatsapp.messagesButton(
bodyText: "Do you love flutter",
buttons: [
{"id": "yes", "text": "π Yes"},
{"id": "no", "text": "β No"}
]
);
π Upload Media to WhatsApp Business
mediaFile
- the file object to be sendmediaName
- the name of file
You need third-party packages for media uploads, for example image_picker for uploading images.
final ImagePicker _picker = ImagePicker();
final XFile? image = await _picker.pickImage(source: ImageSource.gallery);
whatsapp.uploadMedia(
mediaFile: image,
mediaName: "Flutter Logo"
);
π Delete uploaded media
mediaId
- id of media file
whatsapp.deleteMedia(
mediaId: "1000000000000000"
);
π Retrive URL of media
mediaId
- id of media file
whatsapp.getMediaUrl(
mediaId: "1000000000000000"
);
π Update WhatsApp Business Account Details
businessAddress
- address of businessbusinessDescription
- description of businessbusinessIndustry
- industry of businessbusinessAbout
- about of your businessbusinessEmail
- email of your businessbusinessWebsites
- list of website to updatebusinessProfileId
- image handle id to update profile picture of business
whatsapp.updateProfile(
businessAbout: "A.I.",
businessWebsites: ["https://tonystark.com"], //list of website
businessAddress: "New York",
businessDescription: "You know who i am, the Ironman",
businessEmail: "[email protected]",
businessIndustry: "A.I",
businessProfileId: "10203949568543" //image handler id
);
π Set Two Step Verification Code
pin
- 6-digit pin for two step verification.
whatsapp.setTwoStepVerification(
pin:"123456"
);
You are welcome to open a ticket on github if any problems arise. New ideas are always welcome.
Copyright Β© 2022 Rohit Chouhan. Licensed under the MIT LICENSE.