3

Is there a way of adding a user to a Twilio channel using the REST API?

from twilio.rest import Client

# Initialize the client
account = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
token = "your_auth_token"
client = Client(account, token)

# Update the channel
user = client.chat \
                .services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").users.list()[0]
channel = client.chat \
                .services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") \
                .channels("CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").list()[0]
# How to add user to channel?
Alex
  • 3,946
  • 11
  • 38
  • 66

1 Answers1

8

Twilio developer evangelist here.

You can add a member to a channel by creating a member resource using your user's identity. So following on from your code you would need:

channel.members.create(user.identity)

Let me know if that helps.

philnash
  • 70,667
  • 10
  • 60
  • 88