<?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 Shashank on Medium]]></title>
        <description><![CDATA[Stories by Shashank on Medium]]></description>
        <link>https://medium.com/@shashank.shashi2?source=rss-9fed5903ad26------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GbXc3Yfiqed6jXAB_J72pA.jpeg</url>
            <title>Stories by Shashank on Medium</title>
            <link>https://medium.com/@shashank.shashi2?source=rss-9fed5903ad26------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 14:53:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shashank.shashi2/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[Creating a slack bot]]></title>
            <link>https://medium.com/@shashank.shashi2/creating-a-slack-bot-93191ab526f2?source=rss-9fed5903ad26------2</link>
            <guid isPermaLink="false">https://medium.com/p/93191ab526f2</guid>
            <category><![CDATA[slackbot]]></category>
            <category><![CDATA[slack]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Shashank]]></dc:creator>
            <pubDate>Tue, 28 Sep 2021 11:58:26 GMT</pubDate>
            <atom:updated>2021-09-28T11:58:26.324Z</atom:updated>
            <content:encoded><![CDATA[<p>Slack bots are a great way for people to quickly access information about any events. More often than not, any user who has slack as their method of communication in an organisation would have their slack open most of the time, and it would be great if there was a way to pass on relevant information, which would act as a reminder to users when it’s needed.</p><p>There arouse a requirement in our organisation to have some people available on-call post office hours once/twice a month on a round robin basis. This looked like a place where a slack bot could add value by reminding people of their on-call on a particular day. As a bonus it would also be great if we can easily show people the schedule of on-calls for that week right on slack.</p><p>With these use-cases in mind I set out to build a slack bot by visiting the official documentation for creating one <a href="https://api.slack.com/start/building">https://api.slack.com/start/building</a>.</p><p>First, we need to create a slack app by visiting <a href="https://api.slack.com/apps">https://api.slack.com/apps</a> and clicking on “Create Apps” button. Here you would be shown couple of options on how you would like to configure your slack bot’s scopes. We can go ahead with “From scratch” if you would like to go through each option before enable/disabling them.</p><p>Go ahead and give your bot a name. Select a workspace that you would like to have your bot deployed on and you are good to start working on your bot!</p><p>Once we are inside the application we need to setup “Add features and functionality” with configs required for bot. In my case I just needed bots and permissions configured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8S3huflfROAFYDgqK4teFw.png" /></figure><p>You can get access to your user and bot tokens on “OAuth &amp; Permissions” section under “Settings” in the left panel as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*GTyweV2MtrHSuFSBgC9OLw.png" /></figure><p>Of these, <strong>Bot User OAuth Token </strong>would be used to send messages, set Home screen views etc.. and <strong>User OAuth Token </strong>would be used wherever the current user’s identity/information is required.</p><p>Now that the configurations are finally done, we can begin to code out our On-Call application. I chose to do this in javascript, but you can do this with any language of your choice.</p><p>There is a package called <a href="https://www.npmjs.com/package/@slack/web-api">slack/web-api</a> that serves as a nice abstraction for all the slack apis that we want to use and we add that as a dependency.</p><p>In our code, we can go ahead and initialise this with our bot token like</p><pre><em>const </em>{ WebClient, LogLevel } = require(&quot;@slack/web-api&quot;);</pre><pre><em>const </em>web = <em>new </em>WebClient(SLACK_BOT_WEB_API_TOKEN, {<br>  logLevel: LogLevel.<em>DEBUG</em>,<br>});</pre><p>For my use-case, I already had a list of emails and dates for the On-call schedules and I needed a way to find the right slack user and send them a message reminding them that they are on-call today. We can use the<em> users.lookupByEmail</em> function exposed by WebClient to fetch user details by email and send then a message through <em>chat.postMessage</em></p><pre><em>try </em>{<br>  <em>const </em>{ user } = <em>await </em>web.users.lookupByEmail({ email });<br>  <em>if </em>(user?.id) {<br>    <em>await </em>web.chat.postMessage({<br>      text: &#39;You are on call today!&#39;,<br>      channel: res.user.id,<br>    });<br>  } <em>else </em>{<br>    console.log(&#39;Failed fetching user by email&#39;);<br>  }<br>} <em>catch </em>(e) {<br>  console.log(e);<br>}</pre><p>Now provided the email of the user who is on-call for a particular day, the above code would trigger a message to them on slack (I haven’t shared the code to fetch user on-call for a particular day as that wasn’t relevant for demonstrating functionalities of slack).</p><p>For the second part, I wanted to add a Home tab for the slack bot that would show a user’s upcoming on-call dates and the week’s on-call schedule. For that, the Home Tab switch needs to be enabled inside “App Home” section in left hand panel, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MGahus5qBuz0FtBnKyADSA.png" /></figure><p>For designing the views that we want shown in slack bot’s home, we would have to build out a view and publish it using the <em>views.publish </em>function.</p><p>For visualizing how the views are going to come out, we can use <a href="https://app.slack.com/block-kit-builder/T1JDD1QH4#%7B%22blocks%22:%5B%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22Hello,%20Assistant%20to%20the%20Regional%20Manager%20Dwight!%20*Michael%20Scott*%20wants%20to%20know%20where%20you&#39;d%20like%20to%20take%20the%20Paper%20Company%20investors%20to%20dinner%20tonight.%5Cn%5Cn%20*Please%20select%20a%20restaurant:*%22%7D%7D,%7B%22type%22:%22divider%22%7D,%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22*Farmhouse%20Thai%20Cuisine*%5Cn:star::star::star::star:%201528%20reviews%5Cn%20They%20do%20have%20some%20vegan%20options,%20like%20the%20roti%20and%20curry,%20plus%20they%20have%20a%20ton%20of%20salad%20stuff%20and%20noodles%20can%20be%20ordered%20without%20meat!!%20They%20have%20something%20for%20everyone%20here%22%7D,%22accessory%22:%7B%22type%22:%22image%22,%22image_url%22:%22https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg%22,%22alt_text%22:%22alt%20text%20for%20image%22%7D%7D,%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22*Kin%20Khao*%5Cn:star::star::star::star:%201638%20reviews%5Cn%20The%20sticky%20rice%20also%20goes%20wonderfully%20with%20the%20caramelized%20pork%20belly,%20which%20is%20absolutely%20melt-in-your-mouth%20and%20so%20soft.%22%7D,%22accessory%22:%7B%22type%22:%22image%22,%22image_url%22:%22https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg%22,%22alt_text%22:%22alt%20text%20for%20image%22%7D%7D,%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22*Ler%20Ros*%5Cn:star::star::star::star:%202082%20reviews%5Cn%20I%20would%20really%20recommend%20the%20%20Yum%20Koh%20Moo%20Yang%20-%20Spicy%20lime%20dressing%20and%20roasted%20quick%20marinated%20pork%20shoulder,%20basil%20leaves,%20chili%20&amp;%20rice%20powder.%22%7D,%22accessory%22:%7B%22type%22:%22image%22,%22image_url%22:%22https://s3-media2.fl.yelpcdn.com/bphoto/DawwNigKJ2ckPeDeDM7jAg/o.jpg%22,%22alt_text%22:%22alt%20text%20for%20image%22%7D%7D,%7B%22type%22:%22divider%22%7D,%7B%22type%22:%22actions%22,%22elements%22:%5B%7B%22type%22:%22button%22,%22text%22:%7B%22type%22:%22plain_text%22,%22text%22:%22Farmhouse%22,%22emoji%22:true%7D,%22value%22:%22click_me_123%22%7D,%7B%22type%22:%22button%22,%22text%22:%7B%22type%22:%22plain_text%22,%22text%22:%22Kin%20Khao%22,%22emoji%22:true%7D,%22value%22:%22click_me_123%22,%22url%22:%22https://google.com%22%7D,%7B%22type%22:%22button%22,%22text%22:%7B%22type%22:%22plain_text%22,%22text%22:%22Ler%20Ros%22,%22emoji%22:true%7D,%22value%22:%22click_me_123%22,%22url%22:%22https://google.com%22%7D%5D%7D%5D%7D">Block-kit-builder</a> and copy paste the json once your template is ready.</p><pre><em>const </em>response = <em>await </em>web.views.publish({<br>  user_id: user?.id,<br>  view: {<br>    &quot;type&quot;: &quot;home&quot;,<br>    &quot;title&quot;: {<br>      &quot;type&quot;: &quot;plain_text&quot;,<br>      &quot;text&quot;: &quot;On-Call&quot;<br>    },<br>    &quot;blocks&quot;: [{<br>      &quot;type&quot;: &quot;section&quot;,<br>      &quot;text&quot;: {<br>         &quot;type&quot;: &quot;mrkdwn&quot;,<br>         &quot;text&quot;: &quot;Test&quot;<br>      }<br>    }], // Use view built from block-kit-builder<br>  },<br>  trigger_id: &quot;BASE_VIEW&quot;,<br>});</pre><p>Above function would update the home tab of the slack bot for the user id mentioned with views specified.</p><p>At this point we have a functioning slack bot that can be used, and if we want this bot to be installed for all employees in workspace, we need to modify behaviour given on Basic Information &gt;Install your app.</p><p>Thank you for sticking around this long! Hope this turned out to be a useful resource in your efforts to build a slack bot yourself! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93191ab526f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Native modules for IOS: React-Native]]></title>
            <link>https://medium.com/@shashank.shashi2/implementing-native-modules-for-ios-react-native-bcb76be696ea?source=rss-9fed5903ad26------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcb76be696ea</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[native-modules]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Shashank]]></dc:creator>
            <pubDate>Wed, 24 Jan 2018 07:51:37 GMT</pubDate>
            <atom:updated>2018-01-24T07:51:37.381Z</atom:updated>
            <content:encoded><![CDATA[<p>React native is a powerful tool because it lets us use native code(Swift/Obj-C in ios and Java/Kotlin in android) and bridge them to access native methods in our react-native JavaScript files.</p><p>This feature can really come in handy when you are building something which is not yet supported by react-native or you have some old native code that you don’t want to re-write in JavaScript.</p><p>I encountered one such case where I wanted to clear all cookies for <a href="https://facebook.github.io/react-native/docs/webview.html">WebView</a> and there wasn’t any way to achieve this in react-native. The examples in ios <a href="https://facebook.github.io/react-native/docs/native-modules-ios.html">Native Module</a> were all in Objective-C and I wanted to implement this using Swift.</p><p>Start with opening your ios project for react-native under YourReactNativeProject/ios/YourReactNativeProject.xcodeproj or YourReactNativeProject/ios/YourReactNativeProject.xcworkspace if you have made a previous pod install. First create a new swift file and name it CookieManager under your project directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*91yMjfncF4j-_91wUOUA2A.png" /></figure><p>When you create a Swift file you should be prompted to create a bridging header. Inside the bridging header add an import statment</p><pre>#import &quot;RCTBridgeModule.h&quot;</pre><p>Inside your CookieManager.swift file</p><pre>import Foundation</pre><pre>@objc(CookieManager)<br>class CookieManager: NSObject {<br>  <br>  @objc func clearCookies() -&gt; Void {<br>    // Remove all cache<br>    URLCache.shared.removeAllCachedResponses()<br>    <br>    // Delete any associated cookies<br>    if let cookies = HTTPCookieStorage.shared.cookies {<br>      for cookie in cookies {<br>        HTTPCookieStorage.shared.deleteCookie(cookie)<br>      }<br>    }<br>  }<br>}</pre><p>Unfortunately, we have to provide an Objective-C file that exposes our Swift to the React Native Objective-C framework. Create a new Objective-C file and call it CookieManagerBridge</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*Cy9olZnp7SLa1sYBaESGQA.png" /></figure><p>Inside the CookieManagerBridge.m file you can expose your CookieManager class and clearCookies method</p><pre>#import &lt;Foundation/Foundation.h&gt;</pre><pre>#import &quot;RCTBridgeModule.h&quot;<br>#import &quot;RCTBridge.h&quot;<br>#import &quot;RCTEventDispatcher.h&quot;<br><br>@interface RCT_EXTERN_MODULE(CookieManager, NSObject)<br><br>RCT_EXTERN_METHOD(clearCookies)<br><br>@end</pre><h3><strong>Other Use-cases:</strong></h3><p>If you<strong> </strong>are<strong> </strong>creating a method which requires you to pass parameters to the method, you can do so by modifying your .m and .swift files to one shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*1oJTfsiUMuIHr5l7zNg7wA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*iuRGDtw8Q-wH-xV7ZzB26Q.png" /></figure><p>If you want a list of all supported argument types, you can find them <a href="https://facebook.github.io/react-native/docs/native-modules-ios.html#argument-types">here</a></p><p>Now that all the native part is done, you can import this is your react-native JavaScript file with</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*XvF_PSjyCv7BaABz9xjIzQ.png" /></figure><p>Now if you run the project you can find it working perfectly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcb76be696ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>