0
votes

Hi Twilio Evangelists,

We are using Twilio module Programmable chat and using Javascript Client and Twilio.API C# server APIs.

We want user to see the Channels and Messages for the particular channel but need to refrain them from sending messages, conditionally.

We can keep UI elements disabled, but smart user would still be able to to access the Twilio client, and send message.

2
There is one way to use Twilio WebHook (pre events) onSendingMessage, but that would incur an additional overhead to the server, for each message sent. Thus wouldn't be feasible solution. - Cipher sumeet

2 Answers

0
votes

It is possible.

Permission model docs: https://www.twilio.com/docs/api/chat/guides/permissions

Create a role using REST: https://www.twilio.com/docs/api/chat/rest/roles (note sendMessage permission you need to skip).

Then you have two options -- either to disallow all channel users of service to post messages by default (update DefaultChannelRoleSid for service and add a pre-webhook to assign a role with separate REST request to assign wider role to specific users) or add a pre-webhook on onMemberAdded event blocking the join by default and then adding manually via rest user to channel and assigning member a required role.

You can't do this from inside the webhook processing at the moment, so you will have to trigger some external URL that will issue the REST request.

To update the role of the member of a channel, issue POST request to the member URL providing new RoleSid parameter.

0
votes

Twilio developer evangelist here.

You've pointed out that you could use the webhooks to stop a message being sent, but that's not the solution you want. I would have suggested it though!

Another way would be to use the Programmable Chat REST API to load the Channels and the Messages. That way you could display the messages, but the user would not be logged into the service on the client side. Then, only when you are ready to allow them to send a message, you can initiate the JS Client

One other possibility would be to initiate the JS Client, load all the channels and messages and then discard the client and token.

Let me know if that helps at all.