go-azure-communication-services

module
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: BSD-3-Clause

README

go-azure-communication-services

UNOFFICIAL GoLang SDK for Azure Communication Services with support for identity and rooms and ChatThreads.

usage

get the package

go get github.com/karim-w/go-azure-communication-services

import the package

import (
  "github.com/karim-w/go-azure-communication-services/rooms"
  "github.com/karim-w/go-azure-communication-services/identity"
  "github.com/karim-w/go-azure-communication-services/chat"
)

create an identity client


resourceHost := "my-resource.communication.azure.com" // microsoft calls this endpoint
accessKey := "my-access-key"

roomsClient := rooms.NewClient(resourceHost, accessKey)
identityClient := identity.NewClient(resourceHost, accessKey)

identity

create identity
identity, err := identityClient.CreateIdentity(
context.Background(),
&identity.CreateIdentityOptions{
  CreateTokenWithScopes: []string{"chat"},
  ExpiresInMinutes:      60,
},
)
issue access token
token, err := identityClient.IssueAccessToken(
context.Background(),
acsId,
&identity.IssueAccessTokenOptions{
  Scopes: []string{"chat"},
  ExpiresInMinutes:      60,
},
)
revoke access token
err := identityClient.RevokeAccessToken(
context.Background(),
acsId,
)
delete identity
err := identityClient.DeleteIdentity(
context.Background(),
acsId,
)

rooms

create room
room, err := roomsClient.CreateRoom(
  context.Background(),
  &rooms.CreateRoomOptions{
    ValidFrom: time.Now(),
    ValidUntil: time.Now().Add(time.Hour * 24),
    RoomJoinPolicy: "InviteOnly",
    Participants: []rooms.RoomParticipant{
      CreateRoomParticipant(id, PRESENTER),
      CreateRoomParticipant(id, ATTENDEE),
    },
  },
)
get room
room, err := roomsClient.GetRoom(
  context.Background(),
  roomId,
)
update room
room, err := roomsClient.UpdateRoom(
  context.Background(),
  roomId,
  &rooms.UpdateRoomOptions{
    ValidFrom: time.Now(),
    ValidUntil: time.Now().Add(time.Hour * 24),
    RoomJoinPolicy: "InviteOnly",
  },
)
delete room
err := roomsClient.DeleteRoom(
  context.Background(),
  roomId,
)
get room participants
participants, err := roomsClient.GetRoomParticipants(
  context.Background(),
  roomId,
)
add room participants
participants, err := roomsClient.AddRoomParticipants(
  context.Background(),
  roomId,
  CreateRoomParticipant(id, PRESENTER),
  CreateRoomParticipant(id, ATTENDEE),
)
remove room participants
err := roomsClient.RemoveRoomParticipants(
  context.Background(),
  roomId,
  RemoveRoomParticipant(id),
)
Update room participants
participants, err := roomsClient.UpdateRoomParticipants(
  context.Background(),
  roomId,
  CreateRoomParticipant(id, PRESENTER),
)

Please Refer to the tests for more examples on how to use the rooms SDK.

ChatThreads

Create ChatThread
chatThread, err := chatClient.CreateChatThread(
  context.Background(),
 "test",
 ChatUser{ID: id, DisplayName: "test"},
 ChatUser{ID: id2, DisplayName: "test2"},
)
Delete ChatThread
err := chatClient.DeleteChatThread(
  context.Background(),
  chatThreadId,
)
Add ChatThread Participants
participants, err := chatClient.AddChatParticipants(
  context.Background(),
  chatThreadId,
  ChatUser{ID: id, DisplayName: "test"},
  ChatUser{ID: id2, DisplayName: "test2"},
)
Remove ChatThread Participants
err := chatClient.RemoveChatParticipant(
  context.Background(),
  chatThreadId,
  id,
)

Emails

Send Email
 client := emails.NewClient(host, key, nil)
 payload := emails.Payload{
  Headers: emails.Headers{
   ClientCorrelationID:    "1234",
   ClientCustomHeaderName: "ClientCustomHeaderValue",
  },
  SenderAddress: "<ACS_EMAIL>"
  Content: emails.Content{
   Subject:   "Test email",
   PlainText: "This is a test email",
  },
  Recipients: emails.Recipients{
   To: []emails.ReplyTo{
    {
     Address: "<EMAIL_ADDRESS>",
    },
   },
  },
 }
 result, err := client.SendEmail(context.TODO(), payload)

References

License

BSD 3-Clause License

Author

karim-w

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL