简体   繁体   中英

Twilio Programmable Chat; Stopping client to send message

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM