News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Is there a way to send an SMS message from another user's account with their credentials?
Tags: sms and text messaging
Jun 12, 2022 at 12:09pm   •   3 replies  •  0 likes
Barak Poker

To add some context. We have multiple users that all have their own phone numbers. We would like to be able to automate some SMS notifications from their specific numbers when certain events occur in our system. Per a discussion with RC "support" they said the only way to do this is by generating a token for the user and then sending the SMS with the token. This can be done in our system by storing RC credentials, however, this is not a scalable solution as we add users and they may change their credentials.


Does anyone have any suggestions on how to approach this?

on Jun 13, 2022 at 9:21pm   •  0 likes

I agree with the RC Support provided answer and can't think of another way as you need to authenticate against RC with that user account credentials. Curious why you say this is not scalable as you can do that programmatically in the backend.

2 Answers
answered on Jun 14, 2022 at 7:42am  

@Yatin Gera I understand that I can receive a notification when an SMS is received, but I was to send out an SMS upon an internal event in the system that has nothing to do with SMS exchanges.

For example, if an order is shipped, I want to be able to send an SMS notification from the users direct line notifying them that the order is shipped even if there has never been an SMS communication with the user before. Is this still possible given your proposed solution?


 0
on Jun 15, 2022 at 7:16am   •  0 likes

Ah. My bad. I mistook it as wanting to get notified when a user receives an SMS.
Option 2 I provided above will not work when sending SMS on another user's behalf.

I am not sure if there is any other way to send SMS on behalf of another user. Let me check with other folks if there is a way that can be done without having to log in every time on behalf of the user

on Jun 15, 2022 at 8:41am   •  0 likes

UPDATE
Sending SMS on another user's behalf is not allowed
I don't see any other way to send SMS on another user's behalf other than saving their credentials (which is not recommended unless you are following proper security guidelines).

You could look into JWT and check if you can create a JWT for every user and give it access to only that app so that you end up not saving users' plain passwords in your database

https://developers.ringcentral.com/guide/authentication/jwt/create-jwt

on Jun 17, 2022 at 11:55am   •  2 likes

Yes, JWT is another way lot of our customers are using to bring this use case to light. Only caveat is that you have to create JWT for every extension/user before hand and map it to the from_number, so that we can use that in your code before sending SMS for that number.

Also JWT doesn't change if those users change their credentials, which is a plus.


answered on Jun 13, 2022 at 10:49pm  

From what I can understand, Subscriptions would best suit your use case.
Now with my un derstanding, I see 2 options available here

Option 1

1. Use the super admin credentials to log in using the API. Get the access token. Any logic mechanism should work here (3 Legged OAuth,JWT, Password)
2. Once you generate the access token, get a list of all the extensions using the below API
https://developers.ringcentral.com/api-reference/Extensions/listExtensions
3. Loop over all the extensions, extract the ids and create an event filter for all these extensions of the below notification type
https://developers.ringcentral.com/api-reference/Instant-Message-Event
4. Create a webhook subscription with the above eventType (one line item in the array for each extension)
5. The webhook will be called every time there is a new SMS for any of the extensions

NOTE: You need super admin credentials to create notifications for other extensions

Option 2

1. Let each user log into the app individually and get the access token for the user
2. Once you generate the access token, get the extensions using the below API
https://developers.ringcentral.com/api-reference/User-Settings/readExtension
3. Extract the extension id from the response and create an event filter for the below notification type
https://developers.ringcentral.com/api-reference/Instant-Message-Event
4. Create a webhook subscription with the above eventType
5. Use the same webhook URLs for all the users and make sure
6. The webhook will be called every time there is a new SMS for any of the extensions

NOTE: This will require an additional step where every user will first have to log in individually so that the subscriptions can be created for each one of them

NOTE

Sharing a sample code for the Option 1

const serverUrl = process.env.RC_SERVER_URL;
const clientId = process.env.RC_CLIENT_ID;
const clientSecret = process.env.RC_CLIENT_SECRET;
const username = process.env.RC_USERNAME;
const password = process.env.RC_PASSWORD;

const sdk = new SDK({ server: serverUrl, clientId, clientSecret });
const platform = sdk.platform();
await platform.login({ username, password });
const extensionListResponse = await platform.get('/restapi/v1.0/account/~/extension');
const extensionListBody = await extensionListResponse.json();
const extensionIds = extensionListBody.records.filter(({ type }) => type === 'User').map(({ id }) => id);
const eventFilters = extensionIds.map((id) => `/restapi/v1.0/account/~/extension/${id}/message-store/instant?type=SMS`);
await platform.post('/restapi/v1.0/subscription', {
    deliveryMode: {
        transportType: 'WebHook',
        address: 'your host nam
    },
    expiresIn: 7776000,
    eventFilters,
});

 2
on Jun 14, 2022 at 6:48am   •  0 likes

@Yatin Gera thank you for the response. I think option #2 is close to what I am trying to do, however the problem is that the users may not be logged in at the time. For example, if the "event" that should trigger an automated SMS message occurs during non-business hours the user will not be logged in.


The only solution I can think of storing RC credentials for each user in our DB, but this is not scalable as we add new users with RC accounts or if users change their RC credentials.

on Jun 14, 2022 at 6:55am   •  0 likes

@Barak Poker
You do not need the user's credentials stored in your DB.
When you create a subscription, there is an option to set the expiry of the subscription and you can put that value to 10 years (for example)
That means that once the user has created the subscription, they do not need to be logged in, and even when logged in, the notification will be sent to the webhook whenever a new SMS is received. You can add custom logic to check the timestamp of the SMS and decide to send a notification to the user depending on that.

As I said, the only caveat is that the user will have to set up the subscription one time by login in to the app using their credentials.


I hope this is helpful.
Feel free to reach out in case you have any other queries regarding this.

on Jun 14, 2022 at 8:39am   •  0 likes

@Yatin Gera


Yatin Gera avatar image

Yatin Gera

FOLLOW
  • 413Reputation
  • 61Posts
  • 0Following
  • 0Followers
  • 11/21Joined

I understand that I can receive a notification when an SMS is received, but I was to send out an SMS upon an internal event in the system that has nothing to do with SMS exchanges.


For example, if an order is shipped, I want to be able to send an SMS notification from the users direct line notifying them that the order is shipped even if there has never been an SMS communication with the user before. Is this still possible given your proposed solution?



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us