<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Send Flow &#8211; Chatbot Dojo</title>
	<atom:link href="https://v3.chatbotdojo.com/topic-category/send-flow/feed/" rel="self" type="application/rss+xml" />
	<link>https://v3.chatbotdojo.com</link>
	<description></description>
	<lastBuildDate>Wed, 14 Oct 2020 16:04:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.8.2</generator>

<image>
	<url>https://v3.chatbotdojo.com/wp-content/uploads/2020/07/favicon-56x56.png</url>
	<title>Send Flow &#8211; Chatbot Dojo</title>
	<link>https://v3.chatbotdojo.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to send content with /fb/sending/sendFlow</title>
		<link>https://v3.chatbotdojo.com/topic/send-content-with-fb-sending-sendflow/</link>
		
		<dc:creator><![CDATA[ninjawarrior]]></dc:creator>
		<pubDate>Sat, 26 Sep 2020 14:10:37 +0000</pubDate>
				<guid isPermaLink="false">https://v3.chatbotdojo.com/?post_type=sfwd-topic&#038;p=25317</guid>

					<description><![CDATA[Sending a flow is similar to sending content, but as the name suggests, you are sending your user to an existing flow instead of content created and sent via the API. The curl command as displayed on the ManyChat API Swagger is: The purpose of this API is to send your subscriber to a flow &#8230;<p class="read-more"> <a class="" href="https://v3.chatbotdojo.com/topic/send-content-with-fb-sending-sendflow/"> <span class="screen-reader-text">How to send content with /fb/sending/sendFlow</span> Read More &#187;</a></p>]]></description>
										<content:encoded><![CDATA[
<p>Sending a flow is similar to sending content, but as the name suggests, you are sending your user to an existing flow instead of content created and sent via the API.</p>



<p>The curl command as displayed on the ManyChat API Swagger is:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">curl -X POST "https://api.manychat.com/fb/sending/sendFlow" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"subscriber_id\": 0, \"flow_ns\": \"string\"}"</pre>



<p>The purpose of this API is to send your subscriber to a flow in your ManyChat account..</p>



<h2>Why would you need this?</h2>



<p>The use cases for this API is similar to the sendContent API and ideal if you are using canned massages or manage your account completely in ManyChat.</p>



<p>The format for the content is as follows:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="json" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">{
  "subscriber_id": 0,
  "flow_ns": "string"
}</pre>



<p>This is the default response on a successful request</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">{
  "status": "success"
}
</pre>



<h2><em>How do we use this in our own system?</em></h2>



<p>To build on the job application idea, this API could be helpful if you need to send your user &#8220;canned&#8221; content, like instructions or processes.</p>



<p>What do we need for this to work?</p>



<ul><li>The API for sendFlow</li><li>The flowID from the flow you want to send, in your ManyChat account</li></ul>



<p>First we will add a new function to our class file in classes/manychat.class.php.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="632" data-enlighter-title="" data-enlighter-group="">    /**
     * 
     * @param type $json_message
     * @param type $mc_api
     */
    function sendFlow($subscriber_id, $flow_ns, $mc_api = '123456:ABCDEF')
    {

        $postfields_arr = [
            'subscriber_id' => $subscriber_id,
            'flow_ns'       => $flow_ns
        ];

        $postfields = json_encode($postfields_arr);

        // initialize cURL
        $ch            = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.manychat.com/fb/sending/sendFlow");
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields . PHP_EOL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $headers       = [
            'Authorization: Bearer ' . preg_replace("/^(\w+\s+)/", "", $mc_api),
            'Accept: application/json',
            'Content-Type: application/json'
        ];
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        // make the request
        $server_output = curl_exec($ch);
        curl_close($ch);
        
        $json_obj  = json_decode($server_output);
        $good_call = $json_obj->status;

        if ($good_call == "success") {
            return $json_obj;
        } else {
            return false;
        }
        
    }</pre>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<h2>The PHP/HTML file</h2>



<p>As in the previous sendContent API, I will put the page API for getting flows in this HTML file. Of course in many cases you just use the same flow for a certain project so there may not be the need to have it as flexible as a pull down menu. Hardcoding your flow ID is just fine in such cases. <strong>Simplicity it key!</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;!DOCTYPE html>
&lt;html>
    &lt;head>
        &lt;title>Send Flow&lt;/title>
        &lt;meta charset="UTF-8">
        &lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
        &lt;!--Bootstrap CSS--> 
        &lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    &lt;/head>
    &lt;body style="padding:50px;max-width:600px;">

        &lt;?php
        /*
         * Load the ManyChat Config File
         */
        require_once './config.inc.php';

        /*
         * Create Page and Form
         */
        if (filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING)):

            /*
             * JSON Format  and POST method 
             */

            $flow          = filter_input(INPUT_POST, 'flow_id');
            $subscriber_id = filter_input(INPUT_POST, 'mc_uid');
            
            $sendFlow      = $mc->sendFlow($subscriber_id, $flow, $mc_api);
            if ($sendFlow->status == "success") {
                echo "Your message is sent";
            } else {
                echo "We could not send your message";
            }

        else:
            ?>

            &lt;form method="post" action="&lt;?= filter_input(INPUT_SERVER, 'PHP_SELF'); ?>">

                &lt;div class="form-group">
                    &lt;label for="message_tag">User ID&lt;/label>                
                    &lt;input type="text" class="form-control" value="123654789" id="mc_uid" name="mc_uid" />
                &lt;/div>

                &lt;div class="form-group">
                    &lt;label for="flow_id">New Flow to Send User to (optional)&lt;/label>
                    &lt;?php
                    $page_getFlows = json_decode($mc->getFlows($mc_api));
                    echo "&lt;select name='flow_id' class='form-control'>";
                    echo "&lt;option value=''> -- Select a Flow -- &lt;/option>";
                    foreach ($page_getFlows->flows AS $pageflows) {
                        echo "&lt;option value='$pageflows->flowId'>$pageflows->flowName&lt;/option>";
                    }
                    echo "&lt;/select>";
                    ?>
                &lt;/div>

                &lt;button type="submit" class="btn btn-primary">Send Flow&lt;/button>

            &lt;/form>

        &lt;?php
        endif;
        ?>        

        &lt;!-- Optional JavaScript -->
        &lt;!-- jQuery first, Bootstrap JS -->
        &lt;script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous">&lt;/script>
        &lt;script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous">&lt;/script>
    &lt;/body>
&lt;/html>
</pre>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<p>The above page will look like this:</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="582" height="267" src="https://v3.chatbotdojo.com/wp-content/uploads/2020/09/afbeelding.png" alt="sendflow html form" class="wp-image-25337" srcset="https://v3.chatbotdojo.com/wp-content/uploads/2020/09/afbeelding.png 582w, https://v3.chatbotdojo.com/wp-content/uploads/2020/09/afbeelding-300x138.png 300w, https://v3.chatbotdojo.com/wp-content/uploads/2020/09/afbeelding-400x184.png 400w" sizes="(max-width: 582px) 100vw, 582px" /></figure>



<p>If you have configured it all correctly, you can press the Submit button and the result will be the notice that your message was sent. Just enter your own ManyChat userID in there (normally this field will be a (hidden) field that is, for example, populated through your system) and send a message to yourself.</p>



<p>All that will be returned is the following message in your browser, while the flow contents are sent to your messenger.</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="232" height="136" src="https://v3.chatbotdojo.com/wp-content/uploads/2020/09/image-3.png" alt="" class="wp-image-25309"/></figure>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
