<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Patrick</title>
    <description>The latest articles on DEV Community by Patrick (@factorlive).</description>
    <link>https://dev.to/factorlive</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F391813%2Fac96ded4-8e68-4b40-b180-d1af41c13ade.gif</url>
      <title>DEV Community: Patrick</title>
      <link>https://dev.to/factorlive</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/factorlive"/>
    <language>en</language>
    <item>
      <title>Python Facebook messenger webhook with FastAPI on Glitch</title>
      <dc:creator>Patrick</dc:creator>
      <pubDate>Sat, 15 Aug 2020 17:12:58 +0000</pubDate>
      <link>https://dev.to/factorlive/python-facebook-messenger-webhook-with-fastapi-on-glitch-4n90</link>
      <guid>https://dev.to/factorlive/python-facebook-messenger-webhook-with-fastapi-on-glitch-4n90</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oP1Y4XfL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zbu4maxpcvm05rs7zfep.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oP1Y4XfL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zbu4maxpcvm05rs7zfep.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This webhook can be accessed on &lt;a href="https://glitch.com/~wit-ai-pywebhook"&gt;Glitch&lt;/a&gt; and re-used ("remixed") to start a new project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z52NSJJl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.glitch.com/529fa55b-87a8-4024-9f8a-84d263c206b3%252Fmessenger.png%3Fv%3D1597507445635" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z52NSJJl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.glitch.com/529fa55b-87a8-4024-9f8a-84d263c206b3%252Fmessenger.png%3Fv%3D1597507445635" alt="The facebook messenger output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--36Mvw2cJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.glitch.com/529fa55b-87a8-4024-9f8a-84d263c206b3%252Flogs.png%3Fv%3D1597507449109" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--36Mvw2cJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.glitch.com/529fa55b-87a8-4024-9f8a-84d263c206b3%252Flogs.png%3Fv%3D1597507449109" alt="Logging output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also check out Scott's &lt;a href="https://vimeo.com/417820077"&gt;introduction video&lt;/a&gt; on setting up facebook messenger based on his node.js app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Python 3.6+&lt;/li&gt;
&lt;li&gt;FastAPI&lt;/li&gt;
&lt;li&gt;Uvicorn&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  API Gateway features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GET verification&lt;/strong&gt; of a received &lt;em&gt;challenge&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;POST message reponse&lt;/strong&gt; after validating the signature &lt;em&gt;X-Hub-Signature&lt;/em&gt; of the received message&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Verify the Webhook
&lt;/h1&gt;

&lt;p&gt;The webhook will return the received variable "challenge" as required by &lt;a href="https://developers.facebook.com/docs/messenger-platform/webhook"&gt;Facebook's instructions&lt;/a&gt; to set up a webhook. You will have to add the webhook in your Messenger settings for each App, which you can access on &lt;a href="https://developers.facebook.com/"&gt;Facebook Developers&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EvgVTB8Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.glitch.com/529fa55b-87a8-4024-9f8a-84d263c206b3%252Fappsettings.png%3Fv%3D1597508804453" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EvgVTB8Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.glitch.com/529fa55b-87a8-4024-9f8a-84d263c206b3%252Fappsettings.png%3Fv%3D1597508804453" alt="Added webhook"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Respond to a message received on a Facebook Page
&lt;/h2&gt;

&lt;p&gt;After glueing your app together with a facebook page and this webhook you will be able to focus your &lt;em&gt;pythonista skills&lt;/em&gt; on the responses of your virtual alter ego.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wit.ai Hackathon 3 submission
&lt;/h2&gt;

&lt;p&gt;This webhook will be used as a contribution for the 2020 Facebook Hackathon Series, Hackathon 3 with the submission deadline as of &lt;em&gt;7 September 2020&lt;/em&gt;. This contribution aims to tickle some strategic points out of the judges and particularly encourages all the smart data scientists out there to focus on their algorithmic models to make a compelling case for a friendly, clever and helpful chatbot.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pull Requests, Issues, Comments
&lt;/h2&gt;

&lt;p&gt;All feedback is welcome. Hope to hear if you find this contribution useful. The repo is &lt;a href="https://github.com/factorlive/fbmessenger-pywebhook"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;ToDo list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Refactored &lt;a href="https://fastapi.tiangolo.com/tutorial/dependencies/"&gt;dependency&lt;/a&gt; to check signature&lt;/li&gt;
&lt;li&gt;Util function to package outgoing message&lt;/li&gt;
&lt;li&gt;Full testing coverage with test client&lt;/li&gt;
&lt;li&gt;Add response time to logs&lt;/li&gt;
&lt;li&gt;Explain code line by line in Readme&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>chatbot</category>
      <category>webdev</category>
      <category>serverless</category>
    </item>
    <item>
      <title>Clean Python3.8 setup with Poetry </title>
      <dc:creator>Patrick</dc:creator>
      <pubDate>Wed, 05 Aug 2020 22:27:17 +0000</pubDate>
      <link>https://dev.to/factorlive/clean-python3-8-setup-with-poetry-5dk6</link>
      <guid>https://dev.to/factorlive/clean-python3-8-setup-with-poetry-5dk6</guid>
      <description>&lt;h1&gt;
  
  
  Only use Poetry - no strings attached
&lt;/h1&gt;

&lt;p&gt;The web shows you multiple solutions to get you going in python and many are used in conjunction with other environment setup dependencies even if they don't have to. &lt;/p&gt;

&lt;p&gt;💡 Use Poetry!&lt;/p&gt;

&lt;p&gt;First of all, we assume that you are not working in a docker environment and you are using Poetry for pure development purposes. Moreover, the Python installation should be performed after considering advice on Python's official website. For instance, following this &lt;a href="https://docs.python.org/3.8/using/mac.html"&gt;Link&lt;/a&gt; you can find the installation instructions for Python 3.8 for Mac. &lt;/p&gt;

&lt;p&gt;For this solution, you don't need any of the other tools 🔧 such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;pip&lt;/li&gt;
&lt;li&gt;pipenv&lt;/li&gt;
&lt;li&gt;pipx&lt;/li&gt;
&lt;li&gt;virtualenv&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why would you use Poetry?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Interdependencies issues can be avoided, i.e. a new dependency requiring dependencies will not break your application. Pip refers to specific versions and hence poses this problem. Pip is the straight forward answer if you are about to deploy and not develop the application any further, however. 🚀&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The other listed too tools are not required to run Poetry. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💡 If you face issues with Poetry, do not mix other solutions into your development environment.&lt;/p&gt;

&lt;h1&gt;
  
  
  Install Poetry and initialize project
&lt;/h1&gt;

&lt;p&gt;The installation works by executing the official installation Script with your python3.8:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-sSL&lt;/span&gt; https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;💡 Notice that you need to use python3 or python3.8 depending on your installation. 😞 If you simply use python, your setup will be based on your python2 environment.  &lt;/p&gt;

&lt;p&gt;😠 Don't follow the advice of people who ask you to set up an alias for your python command in your bash/zsh shell. This may break other programs that you use.&lt;/p&gt;

&lt;h1&gt;
  
  
  Starting a new project 🎉
&lt;/h1&gt;

&lt;p&gt;The best way is to create the folder yourself and use Poetry's interactive mode to generate a pyproject.toml file that is your &lt;strong&gt;2020&lt;/strong&gt; replacement for your requirements.txt file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Activating the environment
&lt;/h1&gt;

&lt;p&gt;To activate the environment you need to use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry shell
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The virtual environments are centrally stored and not mixed into your project. So you don't need to worry about your .gitignore file anymore for a venv folder. You can alternatively use different environments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry &lt;span class="nb"&gt;env &lt;/span&gt;use python3.7 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Troubleshooting Poetry for selecting the environment
&lt;/h1&gt;

&lt;p&gt;For Mac users I recommend updating Poetry to the latest version as the environment may not be activated properly. Again, you don't need to use any other dependencies. The point is to avoid unnecessary dependencies, right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;poetry self update --preview
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;More information on the described bug 👉 &lt;a href="https://github.com/python-poetry/poetry/issues/2711"&gt;here&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>python</category>
      <category>2020setup</category>
      <category>poetry</category>
    </item>
  </channel>
</rss>
