<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nikita Singh on Medium]]></title>
        <description><![CDATA[Stories by Nikita Singh on Medium]]></description>
        <link>https://medium.com/@nikitasingh_21691?source=rss-cdbc13689bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*owJXgoHSHjw7N5KW05zf5g.jpeg</url>
            <title>Stories by Nikita Singh on Medium</title>
            <link>https://medium.com/@nikitasingh_21691?source=rss-cdbc13689bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 22:14:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nikitasingh_21691/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Twilio Conversations API with React Native]]></title>
            <link>https://medium.com/@nikitasingh_21691/twilio-conversations-api-with-react-native-872ea68d1ca4?source=rss-cdbc13689bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/872ea68d1ca4</guid>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Nikita Singh]]></dc:creator>
            <pubDate>Mon, 14 Feb 2022 15:38:07 GMT</pubDate>
            <atom:updated>2022-02-14T15:38:07.955Z</atom:updated>
            <content:encoded><![CDATA[<p>You guys must have understood by now that there is no official SDK for Twilio React Native available. However, we can use the Javascript SDK (compatible with React Native) for using Twilio Conversations in our projects.</p><p><strong>Basic Terms:</strong></p><ol><li><strong>Client: </strong>A client is the starting point to the Twilio Conversations functionality. You will have to create a client to access any further API.</li><li><strong>Conversation: </strong>A conversation is the space for chatting.<br>You can add upto1000 participants in a conversation.<br>For Group Chatting, just add more than 2 participants in the conversation.</li><li><strong>Participant: </strong>Participants added to the conversation can chat with each other.</li></ol><h4><strong>Brief:</strong></h4><ol><li>Token generation (Participant based)</li><li>Client creation</li><li>Conversation creation</li><li>Add Participants</li><li>Join Conversation</li><li>Get Conversation</li><li>Add Listeners for messages</li><li>Send Message</li></ol><p>Your Backend will create conversation, add participants to the conversation and will provide you the SID of conversation and token of your participant.</p><p>Let’s move to the Implementation part-</p><p><strong>Step 1:<br></strong>Install the package: npm install — save @twilio/conversations</p><p><a href="http://media.twiliocdn.com/sdk/js/conversations/releases/2.0.1/docs/">http://media.twiliocdn.com/sdk/js/conversations/releases/2.0.1/docs/index.html</a></p><p><strong>Step 2:<br></strong>Get your token and conversation SID from your Backend.</p><p><strong>Step 3:<br></strong>Once you receive your token, create a client at your end.</p><pre>import { Client } from &#39;@twilio/conversations&#39;;</pre><pre>client = new Client(token);<br>client.on(&#39;stateChanged&#39;, async (state) =&gt; {<br>   if (state === &#39;initialized&#39;) {<br>      // Perform Your Action after client is initialized<br>   }<br> });</pre><h4><strong>Step 4:</strong></h4><p>Get the conversation.</p><pre>conversation = await client.getConversationBySid(sid);</pre><p>You can also create a conversation at your end by using this method-</p><pre>const conversation = await client.createConversation({ friendlyName: ‘Test Conversation’ }); <br>// friendlyName must be unique for each conversation.</pre><h4><strong>Step 5:</strong></h4><p>Now that you have the conversation. Join your conversation using</p><pre>await conversation.join();</pre><h4><strong>Step 6:</strong></h4><p>Get all Messages of the conversation</p><pre>await conversation.getMessages();</pre><p>getMessages accept 3 parameters. All 3 are optional.</p><p>1. pageSize(<em>number):</em> Number of messages to be returned at one call. Default is 30, Max is 100.<br>2. Anchor(number): Index of the newest message to fetch<br>3. Direction(“backwards” | “forward”): New to old Messages or vice-versa.</p><p>You can call the method by passing pageSize as 100</p><pre>let allMessages = await conversation.getMessages(100);</pre><p>This method returns an object that has</p><ul><li>hasNextPage: boolean that tells you whether next page is available or not</li><li>hasPrevPage: boolean that tells you whether prev page is available or not</li><li>nextPage: function that you can call to get next page messages</li><li>prevPage: function that you can call to get prev page messages</li><li>Items: array of objects. Each object has a key ‘state’ that has your message details.</li></ul><h4><strong>Step 7:</strong></h4><p>Add Listener to your class for receiving new messages -</p><pre>configureListener = (conversation) =&gt; {<br>  conversation.on(‘messageAdded’, (msg) =&gt; {<br>     // Append to your list<br>   });<br> };</pre><h4><strong>Step 8:</strong></h4><p>Send Your Message using</p><pre>conversation.sendMessage()</pre><p><strong>Send Text Messages</strong></p><pre>conversation.sendMessage(text);</pre><p><strong>Send Media</strong></p><pre>conversation.sendMessage({ contentType: &#39;string&#39;, filename:  &#39;string&#39;, media: string | Blob | Buffer});</pre><p>To share Images, Audio, Video, Files, we will use <a href="https://www.npmjs.com/package/react-native-document-picker">react-native-document-picker</a></p><pre>import DocumentPicker from ‘react-native-document-picker’;</pre><pre>//Open file directory to select media<br>const selectedItem = await DocumentPicker.pickSingle({ presentationStyle: ‘fullScreen’});</pre><pre>//Get Blob from selected Item<br>let result = await fetch(selectedItem?.fileCopyUri);<br>let blobObject = await result.blob();</pre><pre>//Send Media<br>conversation.sendMessage({ contentType: blobObject?._data?.type, filename: blobObject?._data?.name ,media: blobObject });</pre><p>And that’s it. You have Just Implemented Twilio Conversations API.</p><h4>Limitations:</h4><p><a href="https://www.twilio.com/docs/conversations/conversations-limits">https://www.twilio.com/docs/conversations/conversations-limits</a></p><h4>Javascript Api Doc:</h4><p><a href="http://media.twiliocdn.com/sdk/js/conversations/releases/2.0.1/docs/classes/Client.html">http://media.twiliocdn.com/sdk/js/conversations/releases/2.0.1/docs/classes/Client.html</a></p><p>And that’s it. We have just implemented Twilio Conversations successfully .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=872ea68d1ca4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>