1# coding=utf-8
2r"""
3This code was generated by
4\ / _    _  _|   _  _
5 | (_)\/(_)(_|\/| |(/_  v1.0.0
6      /       /
7"""
8
9from twilio.base import deserialize
10from twilio.base import serialize
11from twilio.base import values
12from twilio.base.instance_context import InstanceContext
13from twilio.base.instance_resource import InstanceResource
14from twilio.base.list_resource import ListResource
15from twilio.base.page import Page
16
17
18class ParticipantList(ListResource):
19
20    def __init__(self, version, chat_service_sid, conversation_sid):
21        """
22        Initialize the ParticipantList
23
24        :param Version version: Version that contains the resource
25        :param chat_service_sid: The SID of the Conversation Service that the resource is associated with.
26        :param conversation_sid: The unique ID of the Conversation for this participant.
27
28        :returns: twilio.rest.conversations.v1.service.conversation.participant.ParticipantList
29        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantList
30        """
31        super(ParticipantList, self).__init__(version)
32
33        # Path Solution
34        self._solution = {'chat_service_sid': chat_service_sid, 'conversation_sid': conversation_sid, }
35        self._uri = '/Services/{chat_service_sid}/Conversations/{conversation_sid}/Participants'.format(**self._solution)
36
37    def create(self, identity=values.unset, messaging_binding_address=values.unset,
38               messaging_binding_proxy_address=values.unset,
39               date_created=values.unset, date_updated=values.unset,
40               attributes=values.unset,
41               messaging_binding_projected_address=values.unset,
42               role_sid=values.unset, x_twilio_webhook_enabled=values.unset):
43        """
44        Create the ParticipantInstance
45
46        :param unicode identity: A unique string identifier for the conversation participant as Conversation User.
47        :param unicode messaging_binding_address: The address of the participant's device.
48        :param unicode messaging_binding_proxy_address: The address of the Twilio phone number that the participant is in contact with.
49        :param datetime date_created: The date that this resource was created.
50        :param datetime date_updated: The date that this resource was last updated.
51        :param unicode attributes: An optional string metadata field you can use to store any data you wish.
52        :param unicode messaging_binding_projected_address: The address of the Twilio phone number that is used in Group MMS.
53        :param unicode role_sid: The SID of a conversation-level Role to assign to the participant
54        :param ParticipantInstance.WebhookEnabledType x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
55
56        :returns: The created ParticipantInstance
57        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantInstance
58        """
59        data = values.of({
60            'Identity': identity,
61            'MessagingBinding.Address': messaging_binding_address,
62            'MessagingBinding.ProxyAddress': messaging_binding_proxy_address,
63            'DateCreated': serialize.iso8601_datetime(date_created),
64            'DateUpdated': serialize.iso8601_datetime(date_updated),
65            'Attributes': attributes,
66            'MessagingBinding.ProjectedAddress': messaging_binding_projected_address,
67            'RoleSid': role_sid,
68        })
69        headers = values.of({'X-Twilio-Webhook-Enabled': x_twilio_webhook_enabled, })
70
71        payload = self._version.create(method='POST', uri=self._uri, data=data, headers=headers, )
72
73        return ParticipantInstance(
74            self._version,
75            payload,
76            chat_service_sid=self._solution['chat_service_sid'],
77            conversation_sid=self._solution['conversation_sid'],
78        )
79
80    def stream(self, limit=None, page_size=None):
81        """
82        Streams ParticipantInstance records from the API as a generator stream.
83        This operation lazily loads records as efficiently as possible until the limit
84        is reached.
85        The results are returned as a generator, so this operation is memory efficient.
86
87        :param int limit: Upper limit for the number of records to return. stream()
88                          guarantees to never return more than limit.  Default is no limit
89        :param int page_size: Number of records to fetch per request, when not set will use
90                              the default value of 50 records.  If no page_size is defined
91                              but a limit is defined, stream() will attempt to read the
92                              limit with the most efficient page size, i.e. min(limit, 1000)
93
94        :returns: Generator that will yield up to limit results
95        :rtype: list[twilio.rest.conversations.v1.service.conversation.participant.ParticipantInstance]
96        """
97        limits = self._version.read_limits(limit, page_size)
98
99        page = self.page(page_size=limits['page_size'], )
100
101        return self._version.stream(page, limits['limit'])
102
103    def list(self, limit=None, page_size=None):
104        """
105        Lists ParticipantInstance records from the API as a list.
106        Unlike stream(), this operation is eager and will load `limit` records into
107        memory before returning.
108
109        :param int limit: Upper limit for the number of records to return. list() guarantees
110                          never to return more than limit.  Default is no limit
111        :param int page_size: Number of records to fetch per request, when not set will use
112                              the default value of 50 records.  If no page_size is defined
113                              but a limit is defined, list() will attempt to read the limit
114                              with the most efficient page size, i.e. min(limit, 1000)
115
116        :returns: Generator that will yield up to limit results
117        :rtype: list[twilio.rest.conversations.v1.service.conversation.participant.ParticipantInstance]
118        """
119        return list(self.stream(limit=limit, page_size=page_size, ))
120
121    def page(self, page_token=values.unset, page_number=values.unset,
122             page_size=values.unset):
123        """
124        Retrieve a single page of ParticipantInstance records from the API.
125        Request is executed immediately
126
127        :param str page_token: PageToken provided by the API
128        :param int page_number: Page Number, this value is simply for client state
129        :param int page_size: Number of records to return, defaults to 50
130
131        :returns: Page of ParticipantInstance
132        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantPage
133        """
134        data = values.of({'PageToken': page_token, 'Page': page_number, 'PageSize': page_size, })
135
136        response = self._version.page(method='GET', uri=self._uri, params=data, )
137
138        return ParticipantPage(self._version, response, self._solution)
139
140    def get_page(self, target_url):
141        """
142        Retrieve a specific page of ParticipantInstance records from the API.
143        Request is executed immediately
144
145        :param str target_url: API-generated URL for the requested results page
146
147        :returns: Page of ParticipantInstance
148        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantPage
149        """
150        response = self._version.domain.twilio.request(
151            'GET',
152            target_url,
153        )
154
155        return ParticipantPage(self._version, response, self._solution)
156
157    def get(self, sid):
158        """
159        Constructs a ParticipantContext
160
161        :param sid: A 34 character string that uniquely identifies this resource.
162
163        :returns: twilio.rest.conversations.v1.service.conversation.participant.ParticipantContext
164        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantContext
165        """
166        return ParticipantContext(
167            self._version,
168            chat_service_sid=self._solution['chat_service_sid'],
169            conversation_sid=self._solution['conversation_sid'],
170            sid=sid,
171        )
172
173    def __call__(self, sid):
174        """
175        Constructs a ParticipantContext
176
177        :param sid: A 34 character string that uniquely identifies this resource.
178
179        :returns: twilio.rest.conversations.v1.service.conversation.participant.ParticipantContext
180        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantContext
181        """
182        return ParticipantContext(
183            self._version,
184            chat_service_sid=self._solution['chat_service_sid'],
185            conversation_sid=self._solution['conversation_sid'],
186            sid=sid,
187        )
188
189    def __repr__(self):
190        """
191        Provide a friendly representation
192
193        :returns: Machine friendly representation
194        :rtype: str
195        """
196        return '<Twilio.Conversations.V1.ParticipantList>'
197
198
199class ParticipantPage(Page):
200
201    def __init__(self, version, response, solution):
202        """
203        Initialize the ParticipantPage
204
205        :param Version version: Version that contains the resource
206        :param Response response: Response from the API
207        :param chat_service_sid: The SID of the Conversation Service that the resource is associated with.
208        :param conversation_sid: The unique ID of the Conversation for this participant.
209
210        :returns: twilio.rest.conversations.v1.service.conversation.participant.ParticipantPage
211        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantPage
212        """
213        super(ParticipantPage, self).__init__(version, response)
214
215        # Path Solution
216        self._solution = solution
217
218    def get_instance(self, payload):
219        """
220        Build an instance of ParticipantInstance
221
222        :param dict payload: Payload response from the API
223
224        :returns: twilio.rest.conversations.v1.service.conversation.participant.ParticipantInstance
225        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantInstance
226        """
227        return ParticipantInstance(
228            self._version,
229            payload,
230            chat_service_sid=self._solution['chat_service_sid'],
231            conversation_sid=self._solution['conversation_sid'],
232        )
233
234    def __repr__(self):
235        """
236        Provide a friendly representation
237
238        :returns: Machine friendly representation
239        :rtype: str
240        """
241        return '<Twilio.Conversations.V1.ParticipantPage>'
242
243
244class ParticipantContext(InstanceContext):
245
246    def __init__(self, version, chat_service_sid, conversation_sid, sid):
247        """
248        Initialize the ParticipantContext
249
250        :param Version version: Version that contains the resource
251        :param chat_service_sid: The SID of the Conversation Service that the resource is associated with.
252        :param conversation_sid: The unique ID of the Conversation for this participant.
253        :param sid: A 34 character string that uniquely identifies this resource.
254
255        :returns: twilio.rest.conversations.v1.service.conversation.participant.ParticipantContext
256        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantContext
257        """
258        super(ParticipantContext, self).__init__(version)
259
260        # Path Solution
261        self._solution = {
262            'chat_service_sid': chat_service_sid,
263            'conversation_sid': conversation_sid,
264            'sid': sid,
265        }
266        self._uri = '/Services/{chat_service_sid}/Conversations/{conversation_sid}/Participants/{sid}'.format(**self._solution)
267
268    def update(self, date_created=values.unset, date_updated=values.unset,
269               identity=values.unset, attributes=values.unset,
270               role_sid=values.unset, messaging_binding_proxy_address=values.unset,
271               messaging_binding_projected_address=values.unset,
272               last_read_message_index=values.unset,
273               last_read_timestamp=values.unset,
274               x_twilio_webhook_enabled=values.unset):
275        """
276        Update the ParticipantInstance
277
278        :param datetime date_created: The date that this resource was created.
279        :param datetime date_updated: The date that this resource was last updated.
280        :param unicode identity: A unique string identifier for the conversation participant as Conversation User.
281        :param unicode attributes: An optional string metadata field you can use to store any data you wish.
282        :param unicode role_sid: The SID of a conversation-level Role to assign to the participant
283        :param unicode messaging_binding_proxy_address: The address of the Twilio phone number that the participant is in contact with.
284        :param unicode messaging_binding_projected_address: The address of the Twilio phone number that is used in Group MMS.
285        :param unicode last_read_message_index: Index of last “read” message in the Conversation for the Participant.
286        :param unicode last_read_timestamp: Timestamp of last “read” message in the Conversation for the Participant.
287        :param ParticipantInstance.WebhookEnabledType x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
288
289        :returns: The updated ParticipantInstance
290        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantInstance
291        """
292        data = values.of({
293            'DateCreated': serialize.iso8601_datetime(date_created),
294            'DateUpdated': serialize.iso8601_datetime(date_updated),
295            'Identity': identity,
296            'Attributes': attributes,
297            'RoleSid': role_sid,
298            'MessagingBinding.ProxyAddress': messaging_binding_proxy_address,
299            'MessagingBinding.ProjectedAddress': messaging_binding_projected_address,
300            'LastReadMessageIndex': last_read_message_index,
301            'LastReadTimestamp': last_read_timestamp,
302        })
303        headers = values.of({'X-Twilio-Webhook-Enabled': x_twilio_webhook_enabled, })
304
305        payload = self._version.update(method='POST', uri=self._uri, data=data, headers=headers, )
306
307        return ParticipantInstance(
308            self._version,
309            payload,
310            chat_service_sid=self._solution['chat_service_sid'],
311            conversation_sid=self._solution['conversation_sid'],
312            sid=self._solution['sid'],
313        )
314
315    def delete(self, x_twilio_webhook_enabled=values.unset):
316        """
317        Deletes the ParticipantInstance
318
319        :param ParticipantInstance.WebhookEnabledType x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
320
321        :returns: True if delete succeeds, False otherwise
322        :rtype: bool
323        """
324        headers = values.of({'X-Twilio-Webhook-Enabled': x_twilio_webhook_enabled, })
325
326        return self._version.delete(method='DELETE', uri=self._uri, headers=headers, )
327
328    def fetch(self):
329        """
330        Fetch the ParticipantInstance
331
332        :returns: The fetched ParticipantInstance
333        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantInstance
334        """
335        payload = self._version.fetch(method='GET', uri=self._uri, )
336
337        return ParticipantInstance(
338            self._version,
339            payload,
340            chat_service_sid=self._solution['chat_service_sid'],
341            conversation_sid=self._solution['conversation_sid'],
342            sid=self._solution['sid'],
343        )
344
345    def __repr__(self):
346        """
347        Provide a friendly representation
348
349        :returns: Machine friendly representation
350        :rtype: str
351        """
352        context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
353        return '<Twilio.Conversations.V1.ParticipantContext {}>'.format(context)
354
355
356class ParticipantInstance(InstanceResource):
357
358    class WebhookEnabledType(object):
359        TRUE = "true"
360        FALSE = "false"
361
362    def __init__(self, version, payload, chat_service_sid, conversation_sid,
363                 sid=None):
364        """
365        Initialize the ParticipantInstance
366
367        :returns: twilio.rest.conversations.v1.service.conversation.participant.ParticipantInstance
368        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantInstance
369        """
370        super(ParticipantInstance, self).__init__(version)
371
372        # Marshaled Properties
373        self._properties = {
374            'account_sid': payload.get('account_sid'),
375            'chat_service_sid': payload.get('chat_service_sid'),
376            'conversation_sid': payload.get('conversation_sid'),
377            'sid': payload.get('sid'),
378            'identity': payload.get('identity'),
379            'attributes': payload.get('attributes'),
380            'messaging_binding': payload.get('messaging_binding'),
381            'role_sid': payload.get('role_sid'),
382            'date_created': deserialize.iso8601_datetime(payload.get('date_created')),
383            'date_updated': deserialize.iso8601_datetime(payload.get('date_updated')),
384            'url': payload.get('url'),
385            'last_read_message_index': deserialize.integer(payload.get('last_read_message_index')),
386            'last_read_timestamp': payload.get('last_read_timestamp'),
387        }
388
389        # Context
390        self._context = None
391        self._solution = {
392            'chat_service_sid': chat_service_sid,
393            'conversation_sid': conversation_sid,
394            'sid': sid or self._properties['sid'],
395        }
396
397    @property
398    def _proxy(self):
399        """
400        Generate an instance context for the instance, the context is capable of
401        performing various actions.  All instance actions are proxied to the context
402
403        :returns: ParticipantContext for this ParticipantInstance
404        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantContext
405        """
406        if self._context is None:
407            self._context = ParticipantContext(
408                self._version,
409                chat_service_sid=self._solution['chat_service_sid'],
410                conversation_sid=self._solution['conversation_sid'],
411                sid=self._solution['sid'],
412            )
413        return self._context
414
415    @property
416    def account_sid(self):
417        """
418        :returns: The unique ID of the Account responsible for this participant.
419        :rtype: unicode
420        """
421        return self._properties['account_sid']
422
423    @property
424    def chat_service_sid(self):
425        """
426        :returns: The SID of the Conversation Service that the resource is associated with.
427        :rtype: unicode
428        """
429        return self._properties['chat_service_sid']
430
431    @property
432    def conversation_sid(self):
433        """
434        :returns: The unique ID of the Conversation for this participant.
435        :rtype: unicode
436        """
437        return self._properties['conversation_sid']
438
439    @property
440    def sid(self):
441        """
442        :returns: A 34 character string that uniquely identifies this resource.
443        :rtype: unicode
444        """
445        return self._properties['sid']
446
447    @property
448    def identity(self):
449        """
450        :returns: A unique string identifier for the conversation participant as Conversation User.
451        :rtype: unicode
452        """
453        return self._properties['identity']
454
455    @property
456    def attributes(self):
457        """
458        :returns: An optional string metadata field you can use to store any data you wish.
459        :rtype: unicode
460        """
461        return self._properties['attributes']
462
463    @property
464    def messaging_binding(self):
465        """
466        :returns: Information about how this participant exchanges messages with the conversation.
467        :rtype: dict
468        """
469        return self._properties['messaging_binding']
470
471    @property
472    def role_sid(self):
473        """
474        :returns: The SID of a conversation-level Role to assign to the participant
475        :rtype: unicode
476        """
477        return self._properties['role_sid']
478
479    @property
480    def date_created(self):
481        """
482        :returns: The date that this resource was created.
483        :rtype: datetime
484        """
485        return self._properties['date_created']
486
487    @property
488    def date_updated(self):
489        """
490        :returns: The date that this resource was last updated.
491        :rtype: datetime
492        """
493        return self._properties['date_updated']
494
495    @property
496    def url(self):
497        """
498        :returns: An absolute URL for this participant.
499        :rtype: unicode
500        """
501        return self._properties['url']
502
503    @property
504    def last_read_message_index(self):
505        """
506        :returns: Index of last “read” message in the Conversation for the Participant.
507        :rtype: unicode
508        """
509        return self._properties['last_read_message_index']
510
511    @property
512    def last_read_timestamp(self):
513        """
514        :returns: Timestamp of last “read” message in the Conversation for the Participant.
515        :rtype: unicode
516        """
517        return self._properties['last_read_timestamp']
518
519    def update(self, date_created=values.unset, date_updated=values.unset,
520               identity=values.unset, attributes=values.unset,
521               role_sid=values.unset, messaging_binding_proxy_address=values.unset,
522               messaging_binding_projected_address=values.unset,
523               last_read_message_index=values.unset,
524               last_read_timestamp=values.unset,
525               x_twilio_webhook_enabled=values.unset):
526        """
527        Update the ParticipantInstance
528
529        :param datetime date_created: The date that this resource was created.
530        :param datetime date_updated: The date that this resource was last updated.
531        :param unicode identity: A unique string identifier for the conversation participant as Conversation User.
532        :param unicode attributes: An optional string metadata field you can use to store any data you wish.
533        :param unicode role_sid: The SID of a conversation-level Role to assign to the participant
534        :param unicode messaging_binding_proxy_address: The address of the Twilio phone number that the participant is in contact with.
535        :param unicode messaging_binding_projected_address: The address of the Twilio phone number that is used in Group MMS.
536        :param unicode last_read_message_index: Index of last “read” message in the Conversation for the Participant.
537        :param unicode last_read_timestamp: Timestamp of last “read” message in the Conversation for the Participant.
538        :param ParticipantInstance.WebhookEnabledType x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
539
540        :returns: The updated ParticipantInstance
541        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantInstance
542        """
543        return self._proxy.update(
544            date_created=date_created,
545            date_updated=date_updated,
546            identity=identity,
547            attributes=attributes,
548            role_sid=role_sid,
549            messaging_binding_proxy_address=messaging_binding_proxy_address,
550            messaging_binding_projected_address=messaging_binding_projected_address,
551            last_read_message_index=last_read_message_index,
552            last_read_timestamp=last_read_timestamp,
553            x_twilio_webhook_enabled=x_twilio_webhook_enabled,
554        )
555
556    def delete(self, x_twilio_webhook_enabled=values.unset):
557        """
558        Deletes the ParticipantInstance
559
560        :param ParticipantInstance.WebhookEnabledType x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
561
562        :returns: True if delete succeeds, False otherwise
563        :rtype: bool
564        """
565        return self._proxy.delete(x_twilio_webhook_enabled=x_twilio_webhook_enabled, )
566
567    def fetch(self):
568        """
569        Fetch the ParticipantInstance
570
571        :returns: The fetched ParticipantInstance
572        :rtype: twilio.rest.conversations.v1.service.conversation.participant.ParticipantInstance
573        """
574        return self._proxy.fetch()
575
576    def __repr__(self):
577        """
578        Provide a friendly representation
579
580        :returns: Machine friendly representation
581        :rtype: str
582        """
583        context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
584        return '<Twilio.Conversations.V1.ParticipantInstance {}>'.format(context)
585