|
1 |
| -# Twilio event target for Knative Eventing |
| 1 | +# Event Target for Twilio |
2 | 2 |
|
3 |
| -This event target integrates with Twilio, using received Cloud Event messages to create SMS messages. |
4 |
| - |
5 |
| -## Contents |
6 |
| - |
7 |
| -- [Twilio event target for Knative Eventing](#twilio-event-target-for-knative-eventing) |
8 |
| - - [Contents](#contents) |
9 |
| - - [Prerequisites](#prerequisites) |
10 |
| - - [Controller Deployment](#controller-deployment) |
11 |
| - - [Kubernetes manifests](#kubernetes-manifests) |
12 |
| - - [From code](#from-code) |
13 |
| - - [Creating a Twilio Target](#creating-a-twilio-target) |
14 |
| - - [Status](#status) |
15 |
| - - [Twilio Target as an event Sink](#twilio-target-as-an-event-sink) |
16 |
| - - [Sending SMS to a Twilio Target](#sending-sms-to-a-twilio-target) |
| 3 | +This event Target receives [CloudEvents][ce] and utilizes [Twilio][landing] to enable the creation and delivery of SMS |
| 4 | +messages via event-data and event-occurrence, respectively. |
17 | 5 |
|
18 | 6 | ## Prerequisites
|
19 | 7 |
|
20 |
| -A Twilio account is required to run this target: |
21 |
| - |
22 |
| -* Register a Twilio account |
23 |
| -* Purchase a phone number with |
24 |
| -* Retrieve from Twilio Dashbard Account SID |
25 |
| -* Retrieve from Twilio Dashbard Auth Token |
26 |
| - |
27 |
| -## Controller Deployment |
28 |
| - |
29 |
| -### Kubernetes manifests |
30 |
| - |
31 |
| -// TODO use our images |
32 |
| - |
33 |
| -### From code |
34 |
| - |
35 |
| -You can use the [ko](https://github.com/google/ko) tool to compile and deploy from source. |
36 |
| - |
37 |
| -```console |
38 |
| -ko create -f ./config |
39 |
| -``` |
40 |
| - |
41 |
| -## Creating a Twilio Target |
42 |
| - |
43 |
| -Once the Twilio Target Controller has been deployed along all other needed assets are present we can create integrations by adding TwilioTargets objects. |
44 |
| - |
45 |
| -```yaml |
46 |
| -apiVersion: targets.triggermesh.io/v1alpha1 |
47 |
| -kind: TwilioTarget |
48 |
| -metadata: |
49 |
| - name: <TARGET-NAME> |
50 |
| -spec: |
51 |
| - defaultPhoneFrom: "<PHONE-FROM>" |
52 |
| - defaultPhoneTo: "<PHONE-TO>" |
53 |
| - sid: |
54 |
| - secretKeyRef: |
55 |
| - name: "<YOUR-SID-SECRET>" |
56 |
| - key: "<YOUR-SID-SECRET-KEY>" |
57 |
| - token: |
58 |
| - secretKeyRef: |
59 |
| - name: "<YOUR-TOKEN-SECRET>" |
60 |
| - key: "<YOUR-TOKEN-SECRET-KEY>" |
61 |
| -``` |
| 8 | +1. [Twilio][try] account with access to the [Account SID][sid] & [Access Token][token]. |
| 9 | +1. [Phone Number][pn]. |
62 | 10 |
|
63 |
| -Although `defaultPhoneFrom` is not mandatory you will usually configure it matching the phone number you have purchased at Twilio. |
| 11 | +## Deploying an Instance of the Target |
64 | 12 |
|
65 |
| -On the other hand `defaultPhoneTo` wont be usually informed unless you want all messages to address the same phone number by default. |
| 13 | +Open the Bridge creation screen and add a Target of type `Twilio`. |
66 | 14 |
|
67 |
| -Both configurations can be overrided at every Cloud Event message received at the Target. |
| 15 | + |
68 | 16 |
|
69 |
| -Refer to [Twilio docs for number formating](https://www.twilio.com/docs/lookup/tutorials/validation-and-formatting?code-sample=code-lookup-with-international-formatted-number). |
| 17 | +In the Target creation form, give a name to the event Target and add the following information: |
70 | 18 |
|
71 |
| -### Status |
| 19 | +* **Default source phone number**: Sending phone number, usually configured to the [phone number][pn] purchased at |
| 20 | + Twilio. (Optional) |
| 21 | +* **Default destination**: Phone number to send messages to by default. (Optional) |
| 22 | +* **SID Secret**: Reference to a [TriggerMesh secret][tm-secret] containing the [SID of the Twilio account][sid]. |
| 23 | +* **Token Secret**: Reference to a [TriggerMesh secret][tm-secret] containing an [API Access token][token] for |
| 24 | + authenticating requests against the Twilio API. |
72 | 25 |
|
73 |
| -TwilioTarget requires two Secrets to be provided for SID and Token, once they are present it will create a Knative Service. Controller logs and events can provide detailed information about the process. A Status summary is added to the TwilioTarget object informing of the all conditions that the target needs. |
| 26 | +Both the **Default source phone number** and **Default destination** configurations may be overridden by any |
| 27 | +[CloudEvent][ce] message received by the Target. |
74 | 28 |
|
75 |
| -When ready the `status.address.url` will point to the internal point where Cloud Events should be sent. |
| 29 | +For more information about using Twilio, please refer to the [Twilio documentation][docs]. |
76 | 30 |
|
77 |
| -### Twilio Target as an event Sink |
| 31 | + |
78 | 32 |
|
79 |
| -Twilio Target is addressable, which means you can use it as a Sink for Knative components. |
| 33 | +After submitting the bridge, and allowing some configuration time, a green check mark on the main _Bridges_ page |
| 34 | +indicates that the bridge was successfully created. |
80 | 35 |
|
81 |
| -```yaml |
82 |
| -apiVersion: eventing.knative.dev/v1beta1 |
83 |
| -kind: Trigger |
84 |
| -metadata: |
85 |
| - name: <TRIGGER-NAME> |
86 |
| -spec: |
87 |
| - broker: <BROKER-NAME> |
88 |
| - filter: |
89 |
| - attributes: |
90 |
| - type: <MESSAGE-TYPES-TWILIO-FORMATTED> |
91 |
| - subscriber: |
92 |
| - ref: |
93 |
| - apiVersion: targets.triggermesh.io/v1alpha1 |
94 |
| - kind: TwilioTarget |
95 |
| - name: <TARGET-NAME> |
96 |
| -``` |
| 36 | + |
97 | 37 |
|
98 |
| -### Sending SMS to a Twilio Target |
| 38 | +## Event Types |
99 | 39 |
|
100 |
| -Twilio Target expect a JSON payload at the CloudEvent that includes: |
| 40 | +The Twilio event Target can consume events of any type, however, the Target expects a [JSON][ce-jsonformat] payload at |
| 41 | +the [CloudEvent][ce] with the following properties: |
101 | 42 |
|
102 |
| -* `message`: text to be sent. |
103 |
| -* `media_urls`: array of URLs pointing to JPG, GIF or PNG resources. |
104 |
| -* `from`: phone sourcing the communication. Optional if provided by the TWilioTarget. |
105 |
| -* `to`: phone destination. Optional if provided by the TwilioTarget. |
| 43 | +| Name | Type | Description | |
| 44 | +|------|------|-------------| |
| 45 | +| **message** | string | Text to be sent in the body of the SMS message. | |
| 46 | +| **media_urls** | string | Array of URLs pointing to JPEG, GIF or PNG resources. | |
| 47 | +| **from** | string | Phone number sourcing the communication. Takes precedence over the value from the Twilio Target spec. | |
| 48 | +| **to** | string | Phone number of the destination. Takes precedence over the value from the Twilio Target spec. | |
106 | 49 |
|
107 |
| -You can use `curl` from a container in the cluster pointing to the TwilioTarget exposed URL: |
| 50 | +[landing]: https://www.twilio.com/ |
| 51 | +[try]: https://www.twilio.com/try-twilio |
| 52 | +[pn]: https://www.twilio.com/docs/phone-numbers |
| 53 | +[sid]: https://www.twilio.com/docs/iam/api/account |
| 54 | +[token]: https://www.twilio.com/docs/iam/access-tokens |
| 55 | +[docs]: https://www.twilio.com/docs |
108 | 56 |
|
109 |
| -```console |
110 |
| -curl -v http://twiliotarget-int1-8dc3abc7d44bdd0130bd0a311bea272f.knative-samples.svc.cluster.local |
111 |
| - \ |
112 |
| - -X POST \ |
113 |
| - -H "Content-Type: application/json" \ |
114 |
| - -H "Ce-Specversion: 1.0" \ |
115 |
| - -H "Ce-Type: some.message.type" \ |
116 |
| - -H "Ce-Source: some.origin/intance" \ |
117 |
| - -H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79" \ |
118 |
| - -d '{"message":"Hello from Triggermesh using Twilio!","to": "+1111111111"}' |
119 |
| -``` |
| 57 | +[ce]: https://cloudevents.io/ |
| 58 | +[ce-jsonformat]: https://github.com/cloudevents/spec/blob/v1.0/json-format.md |
| 59 | +[tm-secret]: https://docs.triggermesh.io/guides/secrets/ |
0 commit comments