How to Become a Chatbot Ninja in 7 Days

6+ Preset Formats for your ManyChat coupons, dates and numbers

6+ Preset Formats for your ManyChat coupons, dates and numbers

I noticed a lot of questions about random codes and personally i hate the mc formatting of numbers, so i am letting everybody use a script on our server to do three things:

 

• CREATE ANY RANDOM NUMBER BETWEEN 0 AND [YOUR INPUT]

• CREATE ANY ALPHANUMERIC COUPONCODE [YOUR INPUT] CHARACTERS LONG

• FORMAT ANY NUMBER YOU HAVE INTO [YOUR INPUT] DECIMAL NUMBERS

 

Here is what you have to do:

1. Create any of these four custom fields (the ones you're going to use, this script will write to these exact custom fields:
cbs_random_coupon - TEXT
cbs_random_number - NUMBER
cbs_format_number - NUMBER
cbs_format_number_text - TEXT
cbs_pretty_date - TEXT

2. Go to your dynamic content section and fill in this URL in the Request URL
https://chatbotshop.net/cl-server/freenumbercodes.php

Open the BODY tab, fill this in at the Request Body:

{
"page_id":[select page_id from the [+]Add a Variable link],
"action":"[format_number|format_number_text|random_number|random_coupon|format_date_eu|format_date_us]",
"number_to_format":[select a custom field with a numberfrom the [+]Add a Variable link],
"max_format_number_dec":4,
"max_random_number":1000,
"max_random_coupon":10,
"date_to_format":[your date/time custom field]
}

The action can be any of six:
format_number
format_number_text
random_number
random_coupon
format_date_eu
format_date_us

• The "number_to_format" is a custom field you already have and holds a number you would like to see better formatted, instead of 12.5678666543454, it will now become a custom_field (cbs_format_number), like e.g. 12.57
• We noticed the 0 will still be capped by ManyChat, so we added a new variable, the "number_to_format_text", which will display a TEXT custom field including the trailing 0.
• The format_date_eu|format_date_us will be 30-10-2018 16:30|10-30-2018 16:30

Other variables to set:
"max_format_number_dec":2 = the number of decimals for your number field
"max_random_number":1000 = The max number of your random number, so if this is 15, you will get a random number between 0 and 15.
"max_random_coupon":6 = the number of characters in your coupon.

Enjoy!

 

Rather have the script itself? We'll give it for you to copy-paste and use:

<?php
/**
 * 
 * A lot of time went into the creation of my course and you made a payment to get access
 * Please be kind and do not share this with people who are not a member of my course
 * This is a personal file, provided to YOU, not non paying members
 *
 * freenumbercodes.php
 * 
 * DO NOT RESELL THIS FILE
 * 1 LICENSE IS VALID ONE (1) STUDENT
 *
 * Copyright to ChatbotDojo.com (a Social Source initiative)
 *
 * Bonus Module
 *
 */
header("Content-type: application/json; charset=utf-8");
$json_str        = file_get_contents('php://input');

////------------------------------------- GET AS AN OBJECT
$json_obj                = json_decode($json_str);
$page_id                 = $json_obj->page_id; 
$action                  = $json_obj->action;
$max_random_number       = $json_obj->max_random_number;
$max_random_coupon       = $json_obj->max_random_coupon;
$max_format_number_dec	 = $json_obj->max_format_number_dec;
$number_to_format        = $json_obj->number_to_format;
$date_to_format		 = $json_obj->date_to_format;

////------------------------------------- SECURE/LIMIT USAGE TO OWN PAGES
//$allowed_pages       = array("");  // ,"" YOUR PAGE NUMBER(S) HERE
//if (!in_array($page_id, $allowed_pages))exit; // CHECK YOUR PAGE, IF IT S NOT IN THIS LIST EXIT SCRIPT

////------------------------------------- COUPON FUNCTION
function AlphaNumeric($length){
      $chars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //abcdefghijklmnopqrstuvwxyz
      $clen   = strlen( $chars )-1;
      $id  = '';

      for ($i = 0; $i < $length; $i++) {
              $id .= $chars[mt_rand(0,$clen)];
      }
      return ($id);
}

////------------------------------------- JSON
$myArray               = array("version" => "v2");
$content               = array();
////------------------------------------- SWITCH FOR ACTION
switch ($action) {
    case "random_number":

        // make random number between 0 and $random_number 
        $cbs_random_number     = rand(0,$max_random_number);
        $actionsArray          = array("action" => "set_field_value", "field_name" => "cbs_random_number", "value" => $cbs_random_number); // field name has to pre-exist
        break;

    case "random_coupon":

        // make random code format
        // $length                = explode("_", $random_coupon, 2);
        $cbs_random_coupon     = AlphaNumeric($max_random_coupon);	 
        $actionsArray          = array("action" => "set_field_value", "field_name" => "cbs_random_coupon", "value" => $cbs_random_coupon); // field name has to pre-exist
        break;

    case "format_number":

        // make number format
        $max_format_number_dec = (isset($max_format_number_dec))?$max_format_number_dec:2;
        $cbs_format_number     = number_format($number_to_format, $max_format_number_dec, '.', '');
        $actionsArray          = array("action" => "set_field_value", "field_name" => "cbs_format_number", "value" => $cbs_format_number ); // field name has to pre-exist
        break;

    case "format_number_text":

        // make number format
        $max_format_number_dec = (isset($max_format_number_dec))?$max_format_number_dec:2;
        $cbs_format_number     = number_format($number_to_format, $max_format_number_dec, '.', '');
        $actionsArray          = array("action" => "set_field_value", "field_name" => "cbs_format_number_text", "value" => $cbs_format_number); // field name has to pre-exist
        break;

    case "format_date_eu":

        // make a pretty date
        $cbs_date_to_format     = date_create_from_format('Y-m-d\TH:i:sP', $date_to_format);
        $new_cbs_date_to_format = date_format($cbs_date_to_format, 'd-m-Y H:i'); 
        $actionsArray           = array("action" => "set_field_value", "field_name" => "cbs_pretty_date", "value" => $new_cbs_date_to_format); // field name cbs_date_to_format has to pre-exist
        break;

    case "format_date_us":

        // make a pretty date
        $cbs_date_to_format     = date_create_from_format('Y-m-d\TH:i:sP', $date_to_format);
        $new_cbs_date_to_format = date_format($cbs_date_to_format, 'm-d-Y H:i'); 
        $actionsArray           = array("action" => "set_field_value", "field_name" => "cbs_pretty_date", "value" => $new_cbs_date_to_format); // field name cbs_date_to_format has to pre-exist
        break;	

    default: 
        break;		
}

////------------------------------------- JSON
$content['actions'][]  = $actionsArray;
$myArray['content']    = $content;

////------------------------------------- CONVERT TO JSON
$json = json_encode($myArray, JSON_PRETTY_PRINT);
echo $json;
?>