{"id":3100,"date":"2024-02-28T14:43:29","date_gmt":"2024-02-28T14:43:29","guid":{"rendered":"https:\/\/www.infobip.com\/developers\/?p=3100"},"modified":"2024-02-28T16:49:46","modified_gmt":"2024-02-28T16:49:46","slug":"building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk","status":"publish","type":"post","link":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk","title":{"rendered":"Building a Flask app to text you a random joke using the Infobip Python SDK"},"content":{"rendered":"\n<p>This guide shows you how to build a Flask app using the Infobip Python SDK that can send text messages to your phone. If you want to see the finished code, you can check out <a href=\"https:\/\/github.com\/infobip-community\/jokes-with-flask\" target=\"_blank\" rel=\"noreferrer noopener\">the GitHub repo<\/a>. Read on to see what we built, and how to do it yourself!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Prerequisites<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An <a href=\"https:\/\/www.infobip.com\/docs\/essentials\/create-account\">Infobip account<\/a> (a free trial account works fine)<\/li>\n\n\n\n<li>A little Python knowledge<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Setup<\/h3>\n\n\n\n<p>First, create a new folder in your file system called \u2018jokes-with-python\u2019. This folder will be your working directory for the duration of this guide, and when you run terminal commands, you\u2019ll do so from within this directory.&nbsp;<\/p>\n\n\n\n<p>In a terminal window, navigate to this directory. Create and activate a virtual environment to keep all your project dependencies isolated from the rest of your machine:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python3 -m venv .venv\nsource .venv\/bin\/activate<\/code><\/pre>\n\n\n\n<p>Alternatively, the GitHub repository also includes the necessary configuration to set up a dev container, which will provide you with a working environment in which to write and run your Flask app. Read more about using dev containers in <a href=\"https:\/\/docs.github.com\/en\/codespaces\/setting-up-your-project-for-codespaces\/adding-a-dev-container-configuration\/introduction-to-dev-containers\">GitHub Codespaces<\/a>, <a href=\"https:\/\/www.jetbrains.com\/help\/pycharm\/connect-to-devcontainer.html\">PyCharm<\/a> or <a href=\"https:\/\/code.visualstudio.com\/docs\/devcontainers\/containers\">Visual Studio Code<\/a>.<\/p>\n\n\n\n<p>We\u2019ll be building a tiny Flask application with a single page. That page has a button on it, and when you click that button, it sends a programming-related pun to your phone via SMS.&nbsp;<\/p>\n\n\n\n<p>To do this, we\u2019ll need to install the following Python packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install Flask&nbsp;\npip install jokeapi\npip install infobip-api-python-sdk<\/code><\/pre>\n\n\n\n<p>Flask lets us build and serve an application using Python. <a href=\"https:\/\/github.com\/leet-hakker\/JokeAPI-Python\"><code>jokeapi<\/code><\/a> is a Python wrapper for <a href=\"https:\/\/sv443.net\/jokeapi\/v2\/\">Sv443\u2019s Joke API<\/a>, which we\u2019ll be using to retrieve jokes. Lastly, we\u2019ll need the Infobip SDK to write Pythonic code to send SMS messages.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating our app.py<\/h3>\n\n\n\n<p>When you build a Flask app, you usually put the main entry point for that app in a file or package called <code>app.py<\/code>. Our app is going to be a single file of Python, so we\u2019ll create a file called <code>app.py<\/code> in the top level of our working directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>jokes-with-python\/\n    app.py<\/code><\/pre>\n\n\n\n<p>If you like, you can also run the following command from your working directory to keep a record of your currently installed packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip freeze &gt; requirements.txt<\/code><\/pre>\n\n\n\n<p>That will result in a directory structure like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>jokes-with-python\/\n    app.py\n    requirements.txt<\/code><\/pre>\n\n\n\n<p>Open up your <code>app.py<\/code> file in your code editor of choice, and add the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask\n\napp = Flask(__name__)\n\n@app.route('\/')\ndef index():\n    return \u201chello world\u201d<\/code><\/pre>\n\n\n\n<p>Now run <code>flask run<\/code> from the command line in your working directory. By default, this will serve your Flask app at <a href=\"https:\/\/localhost:5000\">https:\/\/localhost:5000<\/a>, and show you a very simple page with the words \u2018hello world\u2019 on it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Adding an HTML template<\/h3>\n\n\n\n<p>Next, we\u2019ll add some HTML for our app to serve us. Flask requires its HTML files to be in a particular place, so create a new directory underneath your working directory called <code>templates<\/code>. Within that directory, add a file called <code>app.html<\/code>, and add the following code to it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;html&gt;\n   &lt;head&gt;\n       &lt;title&gt;Puns with Python&lt;\/title&gt;\n       &lt;link rel=\"icon\" type=\"image\/favicon\" href=\"https:\/\/avatars.githubusercontent.com\/u\/1288491\"&gt;\n       &lt;link href=\"https:\/\/fonts.googleapis.com\/css2?family=Lora:wght@600&amp;display=swap\" rel=\"stylesheet\"&gt;\n   &lt;\/head&gt;\n   &lt;body&gt;\n       &lt;form action=\"{{ url_for('index')}}\" method=\"POST\"&gt;\n           &lt;button type=\"submit\"&gt;&lt;p&gt;Text me a pun!&lt;\/p&gt;&lt;\/button&gt;\n       &lt;\/form&gt;\n   &lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n\n\n\n<p>Your directory structure now looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>jokes-with-python\/\n    app.py\n    requirements.txt\n    templates\/\n        app.html<\/code><\/pre>\n\n\n\n<p>The <code>&lt;head><\/code> section contains some information to help the browser display our page, such as the title and icon. We also use this to set a font for our page\u2019s content, which can be anything you like.<\/p>\n\n\n\n<p>In the <code>&lt;body&gt;<\/code> section, there\u2019s a button component that lives within an HTML <code>&lt;form&gt;<\/code>. When that button is clicked, it sends a POST request to our index page. To handle this kind of request, we\u2019ll need to update the Python function that Flask runs when we access our index page.<\/p>\n\n\n\n<p>In your <code>app.py<\/code> file, update your imports line to include <code>render_template<\/code> and <code>request<\/code> from Flask:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from Flask import Flask, render_template, request<\/code><\/pre>\n\n\n\n<p>&nbsp;Update your <code>index()<\/code> function as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@app.route('\/', methods=&#91;'GET', 'POST'])\ndef index():\n   if request.method == 'GET':\n       pass\n   else:\n       print(\u2018You clicked the button!\u2019)\n   return render_template('app.html')<\/code><\/pre>\n\n\n\n<p>Here, we\u2019ve updated the <code>@app.route<\/code> decorator to specify that this URL should accept both GET and POST requests, and in the body of the function we use an <code>if<\/code> statement to handle the two types of request differently. <\/p>\n\n\n\n<p>With a POST request, we&#8217;ll run through the <code>else<\/code> statement in our code and hit the print statement. When run our Flask app from a terminal window, and click our button in the browser, we\u2019ll see the results of that print statement in that terminal window.<\/p>\n\n\n\n<p>The last change here is that the function now serves our new HTML, instead of just a string saying \u2018hello world\u2019.<\/p>\n\n\n\n<p>Now, run <code>flask run<\/code> again. Your app now serves a page at <a href=\"https:\/\/localhost:5000\">https:\/\/localhost:5000<\/a> that has a button, and when you click that button, you should see the text \u2018You clicked the button!\u2019 appear in your terminal.<\/p>\n\n\n\n<p>If you like, you can also add some CSS styling to your HTML so that the page looks shiny and cool; in the GitHub repo, the <code>app.html<\/code> file <a href=\"https:\/\/github.com\/infobip-community\/jokes-with-flask\/blob\/45c8a5e2d7e811e5f0cdc49247d291a167d883ea\/templates\/app.html#L6\">includes CSS <\/a>within a <code>&lt;style&gt;<\/code> tag, which can be copy-pasted into your version.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Getting jokes from Sv443\u2019s Joke API<\/h3>\n\n\n\n<p>Next, we\u2019ll add a Python function to query the Joke API. The <code>jokeapi<\/code> library uses asynchronous programming to do this, so we\u2019ll need to use the <code>async<\/code> and <code>await<\/code> keywords in our joke function. Add the following imports into your <code>app.py<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import asyncio\nfrom jokeapi import Jokes<\/code><\/pre>\n\n\n\n<p>Now add the following function:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>async def get_joke_from_api():\n   jokes = await Jokes()\n   joke = await jokes.get_joke(category=&#91;'programming', 'pun'], blacklist=&#91;'nsfw'])\n   if joke&#91;\"type\"] == \"single\":\n       joke = joke&#91;\"joke\"]\n   else:\n       joke = f'{joke&#91;\"setup\"]}\\n\\n{joke&#91;\"delivery\"]}'\n   return joke\n<\/code><\/pre>\n\n\n\n<p>This code comes almost exactly from <a href=\"https:\/\/github.com\/leet-hakker\/JokeAPI-Python#readme\">the example in the <code>jokeapi<\/code> documentation<\/a> &#8211; which makes sense, since we\u2019re following a very obvious use-case for this API! We only make a couple of changes to the documentation example: we specify that we\u2019d like the jokes returned to be in classes of <code>programming<\/code> and <code>pun<\/code>, and that we\u2019d like all our jokes to use work-safe humour.<\/p>\n\n\n\n<p>Now update your <code>index<\/code> function to print a joke when the button is clicked:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@app.route('\/', methods=&#91;'GET', 'POST'])\ndef index():\n   if request.method == 'GET':\n       pass\n   else:\n       joke = asyncio.run(get_joke_from_api())\n       print(joke)\n   return render_template('app.html')<\/code><\/pre>\n\n\n\n<p>Here we use <code>asyncio.run()<\/code> to execute our asynchronous joke function.<\/p>\n\n\n\n<p>Run <code>flask run<\/code> as before, and when you click on the button, you should see a joke printed to your terminal!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Adding SMS messaging to our app<\/h3>\n\n\n\n<p>Now we\u2019ll add some Infobip magic into our app. To get started with this, you\u2019ll need the following bits of information:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Your Infobip API key<\/li>\n\n\n\n<li>Your Infobip Base URL<\/li>\n\n\n\n<li>The number to which you\u2019d like to send SMS messages., If you\u2019re using a trial account, this should be the number you\u2019ve verified in association with your account.<\/li>\n<\/ul>\n\n\n\n<p>You can manage and create API credentials at <a href=\"https:\/\/portal.infobip.com\/dev\/api-keys\">https:\/\/portal.infobip.com\/dev\/api-keys<\/a> after logging in to your Infobip account. Your Base URL is also visible in your portal homepage; see <a href=\"https:\/\/www.infobip.com\/docs\/essentials\/base-url\">the documentation<\/a> for more.<\/p>\n\n\n\n<p>When setting the destination phone number, make sure you\u2019re using the <a href=\"https:\/\/www.infobip.com\/docs\/sms\/deliverability#number-formatting\">correct format<\/a>.<\/p>\n\n\n\n<p>Add these variables to your environment by running the following commands in your terminal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export IB_API_KEY=&lt;your API key goes here&gt;\nexport IB_BASE_URL=&lt;your Base URL goes here&gt;\nexport DESTINATION_NUMBER=&lt;your phone number goes here&gt;<\/code><\/pre>\n\n\n\n<p>The first two variables are used directly by the Infobip Python SDK, and we\u2019ll use the phone number ourselves from code using <code>os.environ<\/code>.<\/p>\n\n\n\n<p>Next, you\u2019ll need to add the following imports to your <code>app.py<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from infobip_channels.sms.channel import SMSChannel\nimport os<\/code><\/pre>\n\n\n\n<p>Next, add another function:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def send_sms_from_app(text):\n   channel = SMSChannel.from_env()\n   sms_response = channel.send_sms_message({\n       'messages': &#91;{\n           'from': 'PythonPuns',\n           'text': text,\n           'destinations': &#91;{\n               'to': os.environ&#91;'DESTINATION_NUMBER']\n           }],\n       }]\n   })\n   print(sms_response)<\/code><\/pre>\n\n\n\n<p>This function uses the Infobip Python SDK to send an SMS message. The first line sets up an SMS Channel using the environment variables that we just set. The next line uses that channel to send a message. To learn more about what each part of the arguments to <code>send_sms_message<\/code> are doing, check out the <a href=\"https:\/\/github.com\/infobip-community\/infobip-api-python-sdk\/\">documentation for the SDK<\/a> and <a href=\"https:\/\/www.infobip.com\/docs\/api\/channels\/sms\/sms-messaging\/outbound-sms\/send-sms-message\">the API endpoint<\/a>.<\/p>\n\n\n\n<p>At the end of this function, we print out the response from the API, so we can know that the SMS message was sent.<\/p>\n\n\n\n<p>Now, we need to actually use this function! Update your `index` function one last time:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@app.route('\/', methods=&#91;'GET', 'POST'])\ndef index():\n   if request.method == 'GET':\n       pass\n   else:\n       joke = asyncio.run(get_joke_from_api())\n       send_sms_from_app(joke)\n   return render_template('app.html')<\/code><\/pre>\n\n\n\n<p>All we\u2019ve changed here is that we&#8217;re now calling our new SMS function with our <code>joke<\/code>, rather than printing the joke to the terminal.<\/p>\n\n\n\n<p>Now, run <code>flask run<\/code> again, click the button, and you should see an SMS message sent to the phone number that you specified in <code>DESTINATION_NUMBER<\/code>!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Going even further<\/h3>\n\n\n\n<p>This toy example could be extended in lots of fun ways. You could add a second button that sends a link to <a href=\"https:\/\/wikipedia.readthedocs.io\/en\/latest\/code.html\">a random Wikipedia page<\/a> to your phone, or include input from the web app itself by adding an <code>&lt;input type=\u201dtext\u201d&gt;<\/code> element to the form in your HTML. If you build anything cool, be sure to head over to <a href=\"https:\/\/discord.com\/invite\/G9Gr6fk2e4\">our Discord<\/a> and share it with us!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide shows you how to build a Flask [&hellip;]<\/p>\n","protected":false},"author":53,"featured_media":3111,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[28,13,264],"tags":[43,76,62],"coauthors":[285],"class_list":["post-3100","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-post","category-python","category-sms","tag-api","tag-sdk","tag-tutorial"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Building a Flask app to text you a random joke using the Infobip Python SDK - Infobip Developers Hub<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building a Flask app to text you a random joke using the Infobip Python SDK - Infobip Developers Hub\" \/>\n<meta property=\"og:description\" content=\"This guide shows you how to build a Flask [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk\" \/>\n<meta property=\"og:site_name\" content=\"Infobip Developers Hub\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/infobip\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-28T14:43:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-28T16:49:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"694\" \/>\n\t<meta property=\"og:image:height\" content=\"451\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Eli Holderness\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InfobipDev\" \/>\n<meta name=\"twitter:site\" content=\"@InfobipDev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eli Holderness\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk\"},\"author\":{\"name\":\"Eli Holderness\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/2d3f818bd258646bc997a3ec04146bbd\"},\"headline\":\"Building a Flask app to text you a random joke using the Infobip Python SDK\",\"datePublished\":\"2024-02-28T14:43:29+00:00\",\"dateModified\":\"2024-02-28T16:49:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk\"},\"wordCount\":1300,\"publisher\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png\",\"keywords\":[\"API\",\"SDK\",\"tutorial\"],\"articleSection\":[\"Blog Post\",\"Python\",\"SMS\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk\",\"url\":\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk\",\"name\":\"Building a Flask app to text you a random joke using the Infobip Python SDK - Infobip Developers Hub\",\"isPartOf\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png\",\"datePublished\":\"2024-02-28T14:43:29+00:00\",\"dateModified\":\"2024-02-28T16:49:46+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#primaryimage\",\"url\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png\",\"contentUrl\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png\",\"width\":694,\"height\":451,\"caption\":\"A blog cover image showing the Python logo on the left and the Infobip logo on the right.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.infobip.com\/developers\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building a Flask app to text you a random joke using the Infobip Python SDK\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#website\",\"url\":\"https:\/\/www.infobip.com\/developers\/\",\"name\":\"Infobip Developers Hub\",\"description\":\"Build meaningful customer relationships across any channel\",\"publisher\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.infobip.com\/developers\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#organization\",\"name\":\"Infobip Developers Hub\",\"url\":\"https:\/\/www.infobip.com\/developers\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2023\/03\/Infobip_logo_favicon.png\",\"contentUrl\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2023\/03\/Infobip_logo_favicon.png\",\"width\":696,\"height\":696,\"caption\":\"Infobip Developers Hub\"},\"image\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/infobip\/\",\"https:\/\/x.com\/InfobipDev\",\"https:\/\/www.youtube.com\/channel\/UCUPSTy53VecI5GIir3J3ZbQ\",\"https:\/\/github.com\/infobip-community\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/2d3f818bd258646bc997a3ec04146bbd\",\"name\":\"Eli Holderness\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/image\/e3fd4a8aa6b78952d057f724bcf1dff0\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2261319993db9030e1328c712ee20e4aaedf2c9cb8e4379ae8af57f2c877d5f4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2261319993db9030e1328c712ee20e4aaedf2c9cb8e4379ae8af57f2c877d5f4?s=96&d=mm&r=g\",\"caption\":\"Eli Holderness\"},\"description\":\"Developer advocate, conference speaker &amp; professional nerd. Likes maths, knitting, and cats.\",\"url\":\"https:\/\/www.infobip.com\/developers\/blog\/author\/eli\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Building a Flask app to text you a random joke using the Infobip Python SDK - Infobip Developers Hub","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk","og_locale":"en_US","og_type":"article","og_title":"Building a Flask app to text you a random joke using the Infobip Python SDK - Infobip Developers Hub","og_description":"This guide shows you how to build a Flask [&hellip;]","og_url":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk","og_site_name":"Infobip Developers Hub","article_publisher":"https:\/\/www.facebook.com\/infobip\/","article_published_time":"2024-02-28T14:43:29+00:00","article_modified_time":"2024-02-28T16:49:46+00:00","og_image":[{"width":694,"height":451,"url":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png","type":"image\/png"}],"author":"Eli Holderness","twitter_card":"summary_large_image","twitter_creator":"@InfobipDev","twitter_site":"@InfobipDev","twitter_misc":{"Written by":"Eli Holderness","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#article","isPartOf":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk"},"author":{"name":"Eli Holderness","@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/2d3f818bd258646bc997a3ec04146bbd"},"headline":"Building a Flask app to text you a random joke using the Infobip Python SDK","datePublished":"2024-02-28T14:43:29+00:00","dateModified":"2024-02-28T16:49:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk"},"wordCount":1300,"publisher":{"@id":"https:\/\/www.infobip.com\/developers\/#organization"},"image":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#primaryimage"},"thumbnailUrl":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png","keywords":["API","SDK","tutorial"],"articleSection":["Blog Post","Python","SMS"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk","url":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk","name":"Building a Flask app to text you a random joke using the Infobip Python SDK - Infobip Developers Hub","isPartOf":{"@id":"https:\/\/www.infobip.com\/developers\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#primaryimage"},"image":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#primaryimage"},"thumbnailUrl":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png","datePublished":"2024-02-28T14:43:29+00:00","dateModified":"2024-02-28T16:49:46+00:00","breadcrumb":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#primaryimage","url":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png","contentUrl":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png","width":694,"height":451,"caption":"A blog cover image showing the Python logo on the left and the Infobip logo on the right."},{"@type":"BreadcrumbList","@id":"https:\/\/www.infobip.com\/developers\/blog\/building-flask-app-to-text-you-a-random-joke-using-the-infobip-python-sdk#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.infobip.com\/developers\/"},{"@type":"ListItem","position":2,"name":"Building a Flask app to text you a random joke using the Infobip Python SDK"}]},{"@type":"WebSite","@id":"https:\/\/www.infobip.com\/developers\/#website","url":"https:\/\/www.infobip.com\/developers\/","name":"Infobip Developers Hub","description":"Build meaningful customer relationships across any channel","publisher":{"@id":"https:\/\/www.infobip.com\/developers\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.infobip.com\/developers\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.infobip.com\/developers\/#organization","name":"Infobip Developers Hub","url":"https:\/\/www.infobip.com\/developers\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/logo\/image\/","url":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2023\/03\/Infobip_logo_favicon.png","contentUrl":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2023\/03\/Infobip_logo_favicon.png","width":696,"height":696,"caption":"Infobip Developers Hub"},"image":{"@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/infobip\/","https:\/\/x.com\/InfobipDev","https:\/\/www.youtube.com\/channel\/UCUPSTy53VecI5GIir3J3ZbQ","https:\/\/github.com\/infobip-community"]},{"@type":"Person","@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/2d3f818bd258646bc997a3ec04146bbd","name":"Eli Holderness","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/image\/e3fd4a8aa6b78952d057f724bcf1dff0","url":"https:\/\/secure.gravatar.com\/avatar\/2261319993db9030e1328c712ee20e4aaedf2c9cb8e4379ae8af57f2c877d5f4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2261319993db9030e1328c712ee20e4aaedf2c9cb8e4379ae8af57f2c877d5f4?s=96&d=mm&r=g","caption":"Eli Holderness"},"description":"Developer advocate, conference speaker &amp; professional nerd. Likes maths, knitting, and cats.","url":"https:\/\/www.infobip.com\/developers\/blog\/author\/eli"}]}},"_links":{"self":[{"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/posts\/3100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/users\/53"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/comments?post=3100"}],"version-history":[{"count":11,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/posts\/3100\/revisions"}],"predecessor-version":[{"id":3345,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/posts\/3100\/revisions\/3345"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/media\/3111"}],"wp:attachment":[{"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/media?parent=3100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/categories?post=3100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/tags?post=3100"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/coauthors?post=3100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}