# How to Handle SMS Opt-Ins

Collecting opt-ins for your SMS recipients is critical to responsible communications. It's also part of [Twilio's Acceptable Use Policy](https://help.twilio.com/hc/en-us/articles/223181808-Restricted-SMS-message-types-using-Twilio). Twilio for Salesforce facilitates opt-in collection and tracking through two custom objects: `Opt_In_Keyword__c` and `Opt_In__c`.

`Opt_In_Keyword__c` allows you to define an opt-in keyword such as "volunteer". When a user sends an SMS message that matches this keyword, an `Opt_In__c record` will be created with their phone number, opt-in status, message text, message SID, the keyword, and a lookup to the contact or lead associated with the phone number.

> \[!NOTE]
>
> If a recipient changes their phone number, they will need to opt-in again. If the Mobile Phone field is updated, the opt-in status will be set to `inactive`. Additionally, if a user replies to your message with an industry-standard block word like `STOP`, the opt-in status will be set to `inactive`.

## Campaign SMS opt-in

`Opt_In_Keyword__c` allows you to associate a keyword with a campaign. When a keyword is associated with a campaign, recipients will not be messaged unless they have an opt-in for that specific keyword. You can create an opt-in keyword by using the Salesforce App Launcher to go to the **Opt-in Keywords** page.

> \[!NOTE]
>
> Choose an opt-in keyword that someone isn't likely to send accidentally. For example, "Yes" would be a poor keyword choice, while "donate2022" might be a much better choice.

Once you have created a keyword, you'll be able to click into its record:

![Details tab showing opt-in keyword 'volunteer' with 1 active and 0 inactive records, owned by Charlie Weems.](https://docs-resources.prod.twilio.com/12327e54d60f3be4391edf053e4fa1aef2ea4e3502f7ea9cd5f20ea8a581043f.png)

Click on the **Related** tab and then click on the **New** button in the **Campaigns**   section:

![Salesforce tab showing related opt-ins and campaigns for volunteer keyword.](https://docs-resources.prod.twilio.com/48390a4f4fc802cb36d39a4754b293b1adc95d5b591675a4a907341877570238.png)

You can now create a campaign that will be associated with the keyword. In this example, we've called it "Volunteer Campaign":

![Form for creating a new campaign with fields for name, type, status, and dates.](https://docs-resources.prod.twilio.com/ebcfa73bcfe72a74a7d0d9ae1cd4edcc6f80edb8b2e8398fe920f8da7b0f196e.png)

![Volunteer campaign planned under Opt-In Keyword with one campaign listed.](https://docs-resources.prod.twilio.com/7434f97c411f2831a454fead17546264162f7e2c96d970a2c1ff4dc5dd560b8f.png)

You can now text to your Salesforce phone number with the keyword — in this example, "volunteer". When you send a text, a new Opt-In Record will be created, related to the keyword, and marked active:

![Opt-In Keyword Details Tab New Opt-In in Keyword.](https://docs-resources.prod.twilio.com/557e61707cdb6a5f65b91b2579ae030128f3f6d519eecc8145b8c2c946ec12aa.png)

If you click into the campaign, you'll see that you need to add opted-in users to the campaign before you can use the [SMS Campaign component](/docs/salesforce/sending-bulk-sms-messages-campaign-members):

![Twilio SMS Broadcasts screen showing 'No Campaign Members' with option to add opt-ins.](https://docs-resources.prod.twilio.com/9ec97847fd599b5f492e85031463607b475e1e2ce4b146928cbc44ea7132d60d.png)

Click the **+ Add Opt-Ins** button to add in all new members who have texted the opt-in keyword:

![Confirmation dialog to add 1 opted-in member to the campaign with options to proceed or cancel.](https://docs-resources.prod.twilio.com/ff7bbdcad5ee7bbc83315b00cb446d4ea82b3fa4dff1788127cf7f7b65d0a8e5.png)

When you now send SMS campaigns, you'll see that opt-ins are reflected in your potential deliverability. Messages will not be sent to a campaign member unless they have opted in using the keyword that corresponds to the campaign.

![Twilio SMS Broadcasts deliverability tab showing 100% success rate with breakdown of undelivered, failed, and blocked rates.](https://docs-resources.prod.twilio.com/639be5c04320331e5822cc873107115fe97e6b49819ab6799ced8e1574070b41.png)

## 1:1 SMS opt-in

In addition to requiring opt-ins for campaigns, you can require opt-ins for use of the [1:1 SMS Messaging component](/docs/salesforce/one-one-sms-messaging-contacts). On the Salesforce **Twilio Configuration** page, go to the **SMS Settings** panel, click on the **Require Opt-In for 1:1 SMS Messaging**   toggle, and then click **Save**   .

![Twilio SMS settings with options to create leads or contacts and opt-in for messaging.](https://docs-resources.prod.twilio.com/87de6acd4ed1fa9c53a79ad643eeb1bc82b48803c1d0c9c64f54fb259866f803.png)

The 1:1 SMS Messaging component will now block message sending unless there is at least one `Opt_in__c` record that matches the user's mobile number. In other words, if a customer has never texted in an opt-in keyword, Salesforce users will be blocked from messaging them.

If a user attempts to message a recipient who does not have an opt-in, they will see this message in both the 1:1 SMS Message component and the [SMS Inbox component](/docs/salesforce/sms-inbox):

![Twilio message screen showing 'Opt-In Required' with a phone icon and 'No Opt-in' text.](https://docs-resources.prod.twilio.com/0ab38b8d0f4076816beb538e5c02340a4295eff85e60c2d9ccda663a2efad13e.png)
