Skip to content

rohit-chouhan/whatsapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

46 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

rohit-chouhan sponsor

WhatsApp API package for flutter, to send message and product information.

WhatsApp Business Configuration

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
);

Short link

πŸ’¬ 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 - pass true to compress the link.
whatsapp.short(
	to: 910000000000,
	message: "Hey",
	compress: true
);
//return : https://wa.me/910000000000?text=Hy

Send template

πŸ’¬ 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 text message

πŸ’¬ 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 media files

πŸ’¬ 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 video
  • mediaId - Use this edge to retrieve and delete media.
whatsapp.messagesMedia(
	to: 910000000000,
	mediaType: "image",
	mediaId: "f043afd0-f0ae-4b9c-ab3d-696fb4c8cd68"
);

Send location details

πŸ’¬ 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 media by link

πŸ’¬ 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 video
  • mediaLink - 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 reaction on message

πŸ’¬ 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 reply on message

πŸ’¬ 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
);

Send reply with media

πŸ’¬ 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 video
  • mediaId - id of media to be replay.
whatsapp.messagesReplyMedia(
	to: 910000000000,
	messageId: "wamid.xxxxxxxxxxxxxxxxxx==",
	mediaType: "image",
	mediaId: "1000000000000000"
);

Send reply with media url

πŸ’¬ 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 video
  • mediaLink - 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 number

πŸ“ž Register a phone number

  • pin is 6-digit pin for Register number.
whatsapp.registerNumber(
	pin:"123456"
);

Deregister a number

πŸ“ž Deregister a phone number

  • pin is 6-digit pin for deregister number.
whatsapp.deregisterNumber(
	pin:"123456"
);

Get Shared WhatsApp Business Account Id

πŸ†” Get Shared WhatsApp Business Account Id

  • inputToken - token generated after embedding the signup flow
whatsapp.getWhatsAppBusinessAccounts(
	inputToken:"EAAFl...."
);

Get Shared WhatsApp Business Account List

πŸ†” Get Shared WhatsApp Business Account List

  • accountId - Business manager account Id
whatsapp.getWhatsAppBusinessAccountsList(
	accountId: 805021500648488
);

Send button options

πŸ”˜ 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 message
  • buttons - 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 files

πŸ“ Upload Media to WhatsApp Business

  • mediaFile - the file object to be send
  • mediaName - 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 media files

πŸ“ Delete uploaded media

  • mediaId- id of media file
whatsapp.deleteMedia(
	mediaId: "1000000000000000"
);

Retrive media url

πŸ“ Retrive URL of media

  • mediaId- id of media file
whatsapp.getMediaUrl(
	mediaId: "1000000000000000"
);

Update Business profile

πŸš€ Update WhatsApp Business Account Details

  • businessAddress - address of business
  • businessDescription - description of business
  • businessIndustry - industry of business
  • businessAbout - about of your business
  • businessEmail - email of your business
  • businessWebsites - list of website to update
  • businessProfileId - 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: "tony@ironman.com",
	businessIndustry: "A.I",
	businessProfileId: "10203949568543" //image handler id
);

Two step verification code

πŸ” Set Two Step Verification Code

  • pin - 6-digit pin for two step verification.
whatsapp.setTwoStepVerification(
	pin:"123456"
);

Contributors

chouhan-rahul

Report bugs or issues

You are welcome to open a ticket on github if any problems arise. New ideas are always welcome.

Copyright and License

Copyright Β© 2022 Rohit Chouhan. Licensed under the MIT LICENSE.