Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all endpoints for the programmable chat api. #81

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ Twilio's TaskRouter API:
- [Workspaces](https://www.twilio.com/docs/api/taskrouter/workspaces)
- [Statistics](https://www.twilio.com/docs/api/taskrouter/workspace-statistics)

Twilio's ProgrammableChat API:

- [Overview](https://www.twilio.com/docs/api/chat/rest)
- [Services](https://www.twilio.com/docs/api/chat/rest/services)
- [Channels](https://www.twilio.com/docs/api/chat/rest/channels)
- [Members](https://www.twilio.com/docs/api/chat/rest/members)
- [Users](https://www.twilio.com/docs/api/chat/rest/users)
- [UserChannels](https://www.twilio.com/docs/api/chat/rest/user-channels)
- [Roles](https://www.twilio.com/docs/api/chat/rest/user-channels)
- [Credentials](https://www.twilio.com/docs/api/chat/rest/credentials)

Twilio Capability Tokens:
- [Worker](https://www.twilio.com/docs/api/taskrouter/worker-js)
- [Calling](https://www.twilio.com/docs/api/client/capability-tokens)
Expand Down
1 change: 1 addition & 0 deletions lib/ex_twilio/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ defmodule ExTwilio.Api do
@spec create(atom, data, list) :: Parser.success | Parser.error
def create(module, data, options \\ []) do
data = format_data(data)

module
|> Url.build_url(nil, options)
|> Api.post!(data, auth_header(options))
Expand Down
2 changes: 2 additions & 0 deletions lib/ex_twilio/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ defmodule ExTwilio.Config do

def task_router_websocket_base_url(), do: "https://event-bridge.twilio.com/v1/wschannels"

def programmable_chat_url(), do: "https://chat.twilio.com/v2"

@doc """
A light wrapper around `Application.get_env/2`, providing automatic support for
`{:system, "VAR"}` tuples.
Expand Down
10 changes: 10 additions & 0 deletions lib/ex_twilio/parent.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule ExTwilio.Parent do
@moduledoc """
This module provides structure for the specification of parents to a resource. It contains
a `module` which should be the full module name of the parent resource, as well as a key
which represents the key that will be matched against the options list to find the `sid` of the
parent resource and place it into the url correctly.
"""
defstruct module: nil,
key: nil
end
21 changes: 19 additions & 2 deletions lib/ex_twilio/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ defmodule ExTwilio.Resource do
Delegates the real work to `ExTwilio.Api.resource_collection_name/1` by
default.

Override in your module before `use ExTwilio.Resource` if you need
Override in your module after `use ExTwilio.Resource` if you need
something different.
"""
def resource_collection_name, do: Url.resource_collection_name(__MODULE__)
Expand All @@ -87,14 +87,31 @@ defmodule ExTwilio.Resource do
CamelCase resource name as it would be used in Twilio's API. Delegates
the real work to `ExTwilio.Api.resource_name/1` by default.

Override in your module before `use ExTwilio.Resource` if you need
Override in your module after `use ExTwilio.Resource` if you need
something different.
"""
def resource_name, do: Url.resource_name(__MODULE__)

@doc """
Parents represent path segments that precede the current resource. For example,
in the path `/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Users` "Services" is
a parent. Parents will always have a key in the next segment. If your parent is under a
submodule of `ExTwilio`, specify your parent using the `ExTwilio.Parent` struct.

Override this method in your resource to specify parents in the order that they will appear
in the path.
"""
@spec parents :: list
def parents, do: []

@doc """
Children represent path segments that come after the current resource. For example,
in the path `/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Users/Active` "Active" is
a child. Children may or may not have a key in the next segment.

Override this method in your resource to specify children in the order that they will appear
in the path.
"""
@spec children :: list
def children, do: []

Expand Down
1 change: 1 addition & 0 deletions lib/ex_twilio/resources/member.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ defmodule ExTwilio.Member do

def parents, do: [:account, :queue]
end

32 changes: 32 additions & 0 deletions lib/ex_twilio/resources/programmable_chat/channel.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
defmodule ExTwilio.ProgrammableChat.Channel do
@moduledoc """
Represents a Channel resource in the Twilio Programmable Chat API.

- [Twilio docs](https://www.twilio.com/docs/api/chat/rest/channels)
"""
defstruct sid: nil,
account_sid: nil,
service_sid: nil,
unique_name: nil,
friendly_name: nil,
attributes: nil,
type: nil,
date_created: nil,
date_updated: nil,
created_by: nil,
members_count: nil,
messages_count: nil,
url: nil,
links: nil

use ExTwilio.Resource, import: [
:stream,
:all,
:find,
:create,
:update,
:destroy
]

def parents, do: [%ExTwilio.Parent{module: ExTwilio.ProgrammableChat.Service, key: :service}]
end
25 changes: 25 additions & 0 deletions lib/ex_twilio/resources/programmable_chat/credential.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule ExTwilio.ProgrammableChat.Credential do
@moduledoc """
Represents a Credential resource in the Twilio Programmable Chat API.

- [Twilio docs](https://www.twilio.com/docs/api/chat/rest/credentials)
"""

defstruct sid: nil,
account_sid: nil,
friendly_name: nil,
type: nil,
sandbox: nil,
date_created: nil,
date_updated: nil,
url: nil

use ExTwilio.Resource, import: [
:stream,
:all,
:find,
:create,
:update,
:destroy
]
end
33 changes: 33 additions & 0 deletions lib/ex_twilio/resources/programmable_chat/member.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
defmodule ExTwilio.ProgrammableChat.Member do
@moduledoc """
Represents a Member resource in the Twilio Programmable Chat API.

- [Twilio docs](https://www.twilio.com/docs/api/chat/rest/members)
"""

defstruct sid: nil,
account_sid: nil,
service_sid: nil,
channel_sid: nil,
identity: nil,
role_sid: nil,
date_created: nil,
date_updated: nil,
last_consumed_message_index: nil,
last_consumption_timestamp: nil,
url: nil

use ExTwilio.Resource, import: [
:stream,
:all,
:find,
:create,
:update,
:destroy
]

def parents, do: [
%ExTwilio.Parent{module: ExTwilio.ProgrammableChat.Service, key: :service},
%ExTwilio.Parent{module: ExTwilio.ProgrammableChat.Channel, key: :channel}
]
end
34 changes: 34 additions & 0 deletions lib/ex_twilio/resources/programmable_chat/message.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
defmodule ExTwilio.ProgrammableChat.Message do
@moduledoc """
Represents a Message resource in the Twilio Programmable Chat API.

- [Twilio docs](https://www.twilio.com/docs/api/chat/rest/messages)
"""

defstruct sid: nil,
account_sid: nil,
service_sid: nil,
to: nil,
from: nil,
date_created: nil,
date_updated: nil,
was_edited: nil,
body: nil,
attributes: nil,
index: nil,
url: nil

use ExTwilio.Resource, import: [
:stream,
:all,
:find,
:create,
:update,
:destroy
]

def parents, do: [
%ExTwilio.Parent{module: ExTwilio.ProgrammableChat.Service, key: :service},
%ExTwilio.Parent{module: ExTwilio.ProgrammableChat.Channel, key: :channel}
]
end
28 changes: 28 additions & 0 deletions lib/ex_twilio/resources/programmable_chat/role.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule ExTwilio.ProgrammableChat.Role do
@moduledoc """
Represents a Message resource in the Twilio Programmable Chat API.

- [Twilio docs](https://www.twilio.com/docs/api/chat/rest/roles)
"""

defstruct sid: nil,
account_sid: nil,
service_sid: nil,
friendly_name: nil,
type: nil,
permissions: nil,
date_created: nil,
date_updated: nil,
url: nil

use ExTwilio.Resource, import: [
:stream,
:all,
:find,
:create,
:update,
:destroy
]

def parents, do: [%ExTwilio.Parent{module: ExTwilio.ProgrammableChat.Service, key: :service}]
end
36 changes: 36 additions & 0 deletions lib/ex_twilio/resources/programmable_chat/service.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule ExTwilio.ProgrammableChat.Service do
@moduledoc """
Represents a Service resource in the Twilio Programmable Chat API.

- [Twilio docs](https://www.twilio.com/docs/api/chat/rest/services)
"""
defstruct sid: nil,
account_sid: nil,
friendly_name: nil,
date_created: nil,
date_updated: nil,
default_service_role_sid: nil,
default_channel_role_sid: nil,
default_channel_creator_role_sid: nil,
typing_indicator_timeout: nil,
read_status_enabled: nil,
consumption_report_interval: nil,
reachability_enabled: nil,
limits: nil,
pre_webhook_url: nil,
post_webhook_url: nil,
webhook_method: nil,
webhook_filters: nil,
notifications: nil,
url: nil,
links: nil

use ExTwilio.Resource, import: [
:stream,
:all,
:find,
:create,
:update,
:destroy
]
end
32 changes: 32 additions & 0 deletions lib/ex_twilio/resources/programmable_chat/user.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
defmodule ExTwilio.ProgrammableChat.User do
@moduledoc """
Represents a User resource in the Twilio Programmable Chat API.

- [Twilio docs](https://www.twilio.com/docs/api/chat/rest/users)
"""

defstruct sid: nil,
account_sid: nil,
service_sid: nil,
role_sid: nil,
identity: nil,
friendly_name: nil,
attributes: nil,
date_created: nil,
date_updated: nil,
is_online: nil,
is_notifiable: nil,
joined_channels_count: nil,
url: nil

use ExTwilio.Resource, import: [
:stream,
:all,
:find,
:create,
:update,
:destroy
]

def parents, do: [%ExTwilio.Parent{module: ExTwilio.ProgrammableChat.Service, key: :service}]
end
26 changes: 26 additions & 0 deletions lib/ex_twilio/resources/programmable_chat/user_channel.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
defmodule ExTwilio.ProgrammableChat.UserChannel do
@moduledoc """
Represents a User Channel resource in the Twilio Programmable Chat API.

- [Twilio docs](https://www.twilio.com/docs/api/chat/rest/user-channels)
"""

defstruct sid: nil,
account_sid: nil,
service_sid: nil,
unread_messages_count: nil,
last_consumed_message_index: nil,
channel: nil,
member: nil

use ExTwilio.Resource, import: [
:stream,
:all
]

def resource_name, do: "Channels"
def parents, do: [
%ExTwilio.Parent{module: ExTwilio.ProgrammableChat.Service, key: :service},
%ExTwilio.Parent{module: ExTwilio.ProgrammableChat.User, key: :user}
]
end
2 changes: 1 addition & 1 deletion lib/ex_twilio/resources/task_router/activity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ defmodule ExTwilio.TaskRouter.Activity do

use ExTwilio.Resource, import: [:stream, :all, :find, :create, :update, :delete]

def parents, do: [:workspace]
def parents, do: [%ExTwilio.Parent{module: ExTwilio.TaskRouter.Workspace, key: :workspace}]
end
2 changes: 1 addition & 1 deletion lib/ex_twilio/resources/task_router/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule ExTwilio.TaskRouter.Event do

use ExTwilio.Resource, import: [:stream, :all, :find]

def parents, do: [:workspace]
def parents, do: [%ExTwilio.Parent{module: ExTwilio.TaskRouter.Workspace, key: :workspace}]
def children, do: [:minutes, :start_date, :end_date, :event_type, :worker_sid,
:task_queue_sid, :workflow_sid, :task_sid, :reservation_sid]
end
5 changes: 4 additions & 1 deletion lib/ex_twilio/resources/task_router/reservation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ defmodule ExTwilio.TaskRouter.Reservation do

use ExTwilio.Resource, import: [:stream, :all, :find, :update]

def parents, do: [:workspace, :task]
def parents, do: [
%ExTwilio.Parent{module: ExTwilio.TaskRouter.Workspace, key: :workspace},
%ExTwilio.Parent{module: ExTwilio.TaskRouter.Task, key: :task}
]
def children, do: [:worker_sid, :reservation_status]
end
2 changes: 1 addition & 1 deletion lib/ex_twilio/resources/task_router/task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ defmodule ExTwilio.TaskRouter.Task do

use ExTwilio.Resource, import: [:stream, :all, :find, :create, :update, :delete]

def parents, do: [:workspace]
def parents, do: [%ExTwilio.Parent{module: ExTwilio.TaskRouter.Workspace, key: :workspace}]
def children, do: [:attributes]
end
10 changes: 8 additions & 2 deletions lib/ex_twilio/resources/task_router/task_queue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ defmodule ExTwilio.TaskRouter.TaskQueue do

use ExTwilio.Resource, import: [:stream, :all, :find, :create, :update, :delete]

def parents, do: [:workspace]
def children, do: [:friendly_name, :evaluate_worker_attributes, :reservation_activity_sid, :assignment_activity_sid, :target_workers]
def parents, do: [%ExTwilio.Parent{module: ExTwilio.TaskRouter.Workspace, key: :workspace}]
def children, do: [
:friendly_name,
:evaluate_worker_attributes,
:reservation_activity_sid,
:assignment_activity_sid,
:target_workers
]
end
Loading