Skip to content

Commit

Permalink
馃帀Source Twilio: New streams Roles and Services (#25783)
Browse files Browse the repository at this point in the history
* Add stream roles and services

* schema fix

* Update docs/integrations/sources/twilio.md

Co-authored-by: sh4sh <6833405+sh4sh@users.noreply.github.com>

* Update airbyte-integrations/connectors/source-twilio/source_twilio/streams.py

Co-authored-by: sh4sh <6833405+sh4sh@users.noreply.github.com>

* Bump metadata.yaml

* add expected records

* add chat to allowed hosts

---------

Co-authored-by: sh4sh <6833405+sh4sh@users.noreply.github.com>
Co-authored-by: marcosmarxm <marcosmarxm@gmail.com>
  • Loading branch information
3 people committed May 23, 2023
1 parent 10c3f4c commit 928cc09
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 24 deletions.
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-twilio/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ COPY main.py ./
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.5.0
LABEL io.airbyte.version=0.6.0
LABEL io.airbyte.name=airbyte/source-twilio
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@
"sync_mode": "incremental",
"destination_sync_mode": "append"
},
{
"stream": {
"name": "services",
"json_schema": {},
"supported_sync_modes": ["full_refresh"]
},
"sync_mode": "full_refresh",
"destination_sync_mode": "overwrite"
},
{
"stream": {
"name": "roles",
"json_schema": {},
"supported_sync_modes": ["full_refresh"]
},
"sync_mode": "full_refresh",
"destination_sync_mode": "overwrite"
},
{
"stream": {
"name": "transcriptions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@
{"stream": "usage_triggers", "data": {"sid": "UTed691d2a56a64c45baa9810c16f5931a", "account_sid": "ACdade166c12e160e9ed0a6088226718fb", "date_created": "2023-02-14T14:34:32Z", "date_updated": "2023-02-14T14:34:32Z", "date_fired": null, "friendly_name": null, "usage_category": "sms", "trigger_by": "usage", "recurring": "", "trigger_value": 1000.0, "current_value": 146.0, "callback_url": "http://www.example.com/", "callback_method": "POST", "usage_record_uri": "/2010-04-01/Accounts/ACdade166c12e160e9ed0a6088226718fb/Usage/Records.json?Category=sms", "uri": "/2010-04-01/Accounts/ACdade166c12e160e9ed0a6088226718fb/Usage/Triggers/UTed691d2a56a64c45baa9810c16f5931a.json", "api_version": "2010-04-01"}, "emitted_at": 1682602977675}
{"stream": "usage_triggers", "data": {"sid": "UT73ded683c9884266befb032487fac75e", "account_sid": "ACdade166c12e160e9ed0a6088226718fb", "date_created": "2023-02-14T14:34:33Z", "date_updated": "2023-02-14T14:34:33Z", "date_fired": null, "friendly_name": null, "usage_category": "sms", "trigger_by": "usage", "recurring": "", "trigger_value": 1000.0, "current_value": 146.0, "callback_url": "http://www.example.com/", "callback_method": "POST", "usage_record_uri": "/2010-04-01/Accounts/ACdade166c12e160e9ed0a6088226718fb/Usage/Records.json?Category=sms", "uri": "/2010-04-01/Accounts/ACdade166c12e160e9ed0a6088226718fb/Usage/Triggers/UT73ded683c9884266befb032487fac75e.json", "api_version": "2010-04-01"}, "emitted_at": 1682602977676}
{"stream": "usage_triggers", "data": {"sid": "UT5b9448b2d4e943539f1bba5f052ef01b", "account_sid": "ACdade166c12e160e9ed0a6088226718fb", "date_created": "2023-02-14T14:34:34Z", "date_updated": "2023-02-14T14:34:34Z", "date_fired": null, "friendly_name": null, "usage_category": "sms", "trigger_by": "usage", "recurring": "", "trigger_value": 1000.0, "current_value": 146.0, "callback_url": "http://www.example.com/", "callback_method": "POST", "usage_record_uri": "/2010-04-01/Accounts/ACdade166c12e160e9ed0a6088226718fb/Usage/Records.json?Category=sms", "uri": "/2010-04-01/Accounts/ACdade166c12e160e9ed0a6088226718fb/Usage/Triggers/UT5b9448b2d4e943539f1bba5f052ef01b.json", "api_version": "2010-04-01"}, "emitted_at": 1682602977678}
{"stream": "roles", "data": {"date_updated": "2023-03-21T13:35:15Z", "friendly_name": "service user", "account_sid": "ACdade166c12e160e9ed0a6088226718fb", "url": "https://chat.twilio.com/v2/Services/IS5fcc074f7ead44c99a0a24a374a7e19f/Roles/RL1c0ab592f9724a10992c2ea29709f6cd", "sid": "RL1c0ab592f9724a10992c2ea29709f6cd", "date_created": "2023-03-21T13:35:15Z", "service_sid": "IS5fcc074f7ead44c99a0a24a374a7e19f", "type": "deployment", "permissions": ["createChannel", "joinChannel", "editOwnUserInfo"]}, "emitted_at": 1684513502733}
{"stream": "services", "data": {"typing_indicator_timeout": 5.0, "date_updated": "2023-03-21T13:35:15Z", "post_webhook_url": null, "read_status_enabled": true, "consumption_report_interval": 10.0, "pre_webhook_retry_count": 0.0, "default_service_role_sid": "RL1c0ab592f9724a10992c2ea29709f6cd", "media": {"compatibility_message": "Media messages are not supported by your client", "size_limit_mb": 150.0}, "default_channel_creator_role_sid": "RL3efa7fddc245451cbb76cde110621614", "reachability_enabled": false, "webhook_filters": null, "post_webhook_retry_count": 0.0, "sid": "IS5fcc074f7ead44c99a0a24a374a7e19f", "pre_webhook_url": null, "notifications": {"removed_from_channel": {"enabled": false}, "log_enabled": false, "added_to_channel": {"enabled": false}, "new_message": {"enabled": false}, "invited_to_channel": {"enabled": false}}, "webhook_method": null, "limits": {"user_channels": 1000.0, "channel_members": 1000.0}, "url": "https://chat.twilio.com/v2/Services/IS5fcc074f7ead44c99a0a24a374a7e19f", "friendly_name": "Default Conversations Service", "account_sid": "ACdade166c12e160e9ed0a6088226718fb", "date_created": "2023-03-21T13:35:15Z", "default_channel_role_sid": "RLca3ff6cb9bc9404caf14e43b63fed446", "links": {"channels": "https://chat.twilio.com/v2/Services/IS5fcc074f7ead44c99a0a24a374a7e19f/Channels", "bindings": "https://chat.twilio.com/v2/Services/IS5fcc074f7ead44c99a0a24a374a7e19f/Bindings", "users": "https://chat.twilio.com/v2/Services/IS5fcc074f7ead44c99a0a24a374a7e19f/Users", "roles": "https://chat.twilio.com/v2/Services/IS5fcc074f7ead44c99a0a24a374a7e19f/Roles"}}, "emitted_at": 1684513526771}
3 changes: 2 additions & 1 deletion airbyte-integrations/connectors/source-twilio/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ data:
hosts:
- api.twilio.com
- monitor.twilio.com
- chat.twilio.com
connectorSubtype: api
connectorType: source
definitionId: b9dc6155-672e-42ea-b10d-9f1f1fb95ab1
dockerImageTag: 0.5.0
dockerImageTag: 0.6.0
dockerRepository: airbyte/source-twilio
githubIssueLabel: source-twilio
icon: twilio.svg
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Roles Schema",
"additionalProperties": true,
"type": ["null", "object"],
"properties": {
"sid": {
"type": ["null", "string"]
},
"account_sid": {
"type": ["null", "string"]
},
"service_sid": {
"type": ["null", "string"]
},
"friendly_name": {
"type": ["null", "string"]
},
"type": {
"type": ["null", "string"]
},
"permissions": {
"type": ["null", "array"],
"items": {
"type": ["null", "string"]
}
},
"date_created": {
"type": ["null", "string"],
"format": "date-time"
},
"date_updated": {
"type": ["null", "string"],
"format": "date-time"
},
"url": {
"type": ["null", "string"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Services Schema",
"additionalProperties": true,
"type": ["null", "object"],
"properties": {
"account_sid": {
"type": ["null", "string"]
},
"consumption_report_interval": {
"type": ["null", "number"]
},
"date_created": {
"type": ["null", "string"],
"format": "date-time"
},
"date_updated": {
"type": ["null", "string"],
"format": "date-time"
},
"default_channel_creator_role_sid": {
"type": ["null", "string"]
},
"default_channel_role_sid": {
"type": ["null", "string"]
},
"default_service_role_sid": {
"type": ["null", "string"]
},
"friendly_name": {
"type": ["null", "string"]
},
"limits": {
"type": ["null", "object"],
"properties": {
"channel_members": {
"type": ["null", "number"]
},
"user_channels": {
"type": ["null", "number"]
}
}
},
"links": {
"type": ["null", "object"],
"properties": {
"channels": {
"type": ["null", "string"]
},
"users": {
"type": ["null", "string"]
},
"roles": {
"type": ["null", "string"]
},
"bindings": {
"type": ["null", "string"]
}
}
},
"notifications": {
"type": ["null", "object"],
"properties": {
"users": {
"type": ["null", "string"]
}
}
},
"post_webhook_url": {
"type": ["null", "string"]
},
"pre_webhook_url": {
"type": ["null", "string"]
},
"pre_webhook_retry_count": {
"type": ["null", "number"]
},
"post_webhook_retry_count": {
"type": ["null", "number"]
},
"reachability_enabled": {
"type": ["null", "boolean"]
},
"read_status_enabled": {
"type": ["null", "boolean"]
},
"sid": {
"type": ["null", "string"]
},
"typing_indicator_timeout": {
"type": ["null", "number"]
},
"url": {
"type": ["null", "string"]
},
"webhook_filters": {
"type": ["null", "array"],
"items": {
"type": ["null", "string"]
}
},
"webhook_method": {
"type": ["null", "string"]
},
"media": {
"type": ["null", "object"],
"properties": {
"size_limit_mb": {
"type": ["null", "number"]
},
"compatibility_message": {
"type": ["null", "string"]
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
OutgoingCallerIds,
Queues,
Recordings,
Roles,
Services,
Transcriptions,
UsageRecords,
UsageTriggers,
Expand Down Expand Up @@ -110,6 +112,8 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
OutgoingCallerIds(**full_refresh_stream_kwargs),
Queues(**full_refresh_stream_kwargs),
Recordings(**incremental_stream_kwargs),
Roles(**full_refresh_stream_kwargs),
Services(**full_refresh_stream_kwargs),
Transcriptions(**full_refresh_stream_kwargs),
UsageRecords(**incremental_stream_kwargs),
UsageTriggers(**full_refresh_stream_kwargs),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pendulum.datetime import DateTime
from requests.auth import AuthBase

TWILIO_CHAT_BASE = "https://chat.twilio.com/v2/"
TWILIO_CONVERSATION_BASE = "https://conversations.twilio.com/v1/"
TWILIO_API_URL_BASE = "https://api.twilio.com"
TWILIO_API_URL_BASE_VERSIONED = f"{TWILIO_API_URL_BASE}/2010-04-01/"
Expand Down Expand Up @@ -443,6 +444,32 @@ class Recordings(IncrementalTwilioStream, TwilioNestedStream):
upper_boundary_filter_field = "DateCreated<"
cursor_field = "date_created"

class Services(TwilioStream):
"""
https://www.twilio.com/docs/chat/rest/service-resource#read-multiple-service-resources
"""

url_base = TWILIO_CHAT_BASE

def path(self, **kwargs):
return "Services"


class Roles(TwilioNestedStream):
"""
https://www.twilio.com/docs/chat/rest/role-resource#read-multiple-role-resources
"""

parent_stream = Services
url_base = TWILIO_CHAT_BASE
uri_from_subresource = False

def path(self, stream_slice: Mapping[str, Any] = None, **kwargs):
return f"Services/{ stream_slice['service_sid'] }/Roles"

def parent_record_to_stream_slice(self, record: Mapping[str, Any]) -> Mapping[str, Any]:
return {"service_sid": record["sid"]}


class Transcriptions(TwilioNestedStream):
"""https://www.twilio.com/docs/voice/api/recording-transcription?code-sample=code-read-list-all-transcriptions&code-language=curl&code-sdk-version=json#read-multiple-transcription-resources"""
Expand Down

0 comments on commit 928cc09

Please sign in to comment.