2
0

(wp) Add custom api host for WP plugin

This commit is contained in:
Baptiste Arnaud
2023-03-09 14:59:23 +01:00
parent 6b08df71ba
commit ddd20f6235
8 changed files with 35 additions and 10 deletions

View File

@ -14,6 +14,8 @@ import { useState } from 'react'
import { BubbleSettings } from '../../../settings/BubbleSettings/BubbleSettings'
import { parseInitBubbleCode } from '../../../snippetParsers'
import { parseDefaultBubbleTheme } from '../../Javascript/instructions/JavascriptBubbleInstructions'
import { isCloudProdInstance } from '@/utils/helpers'
import { env, getViewerUrl } from 'utils'
type Props = {
publicId: string
@ -29,6 +31,9 @@ export const WordpressBubbleInstructions = ({ publicId }: Props) => {
const initCode = parseInitBubbleCode({
typebot: publicId,
apiHost: isCloudProdInstance
? undefined
: env('VIEWER_INTERNAL_URL') ?? getViewerUrl(),
theme: {
...theme,
chatWindow: {

View File

@ -11,6 +11,8 @@ import {
import { useState } from 'react'
import { PopupSettings } from '../../../settings/PopupSettings'
import { parseInitPopupCode } from '../../../snippetParsers/popup'
import { isCloudProdInstance } from '@/utils/helpers'
import { env, getViewerUrl } from 'utils'
type Props = {
publicId: string
@ -20,6 +22,9 @@ export const WordpressPopupInstructions = ({ publicId }: Props) => {
const initCode = parseInitPopupCode({
typebot: publicId,
apiHost: isCloudProdInstance
? undefined
: env('VIEWER_INTERNAL_URL') ?? getViewerUrl(),
autoShowDelay,
})

View File

@ -11,6 +11,8 @@ import {
} from '@chakra-ui/react'
import { useState } from 'react'
import { StandardSettings } from '../../../settings/StandardSettings'
import { isCloudProdInstance } from '@/utils/helpers'
import { env, getViewerUrl } from 'utils'
type Props = {
publicId: string
@ -73,8 +75,10 @@ const parseWordpressShortcode = ({
height?: string
publicId: string
}) => {
return `[typebot typebot="${publicId}"${width ? ` width="${width}"` : ''}${
height ? ` height="${height}"` : ''
}]
return `[typebot typebot="${publicId}"${
isCloudProdInstance
? ''
: ` apiHost="${env('VIEWER_INTERNAL_URL') ?? getViewerUrl()}"`
}${width ? ` width="${width}"` : ''}${height ? ` height="${height}"` : ''}]
`
}

View File

@ -28,6 +28,10 @@ You can use these variables anywhere on your typebot. For more informations, che
There is an a box where there is a list of URLs it localises, one of them was https://cdn.jsdelivr.net. This URL should be removed from it since it is used to import the embed library.
## You have litespeed with cache enabled
Make sure to insert `web.js` and `typebot` in the JS Excludes textbox and JS Deferred Excludes under Tuning Settings.
### You have a cache plugin
Plugins like WP Rocket prevent Typebot to work.

View File

@ -1,6 +1,6 @@
{
"name": "wordpress",
"version": "3.1.3",
"version": "3.1.4",
"main": "index.js",
"repository": "https://github.com/baptisteArno/typebot.io",
"author": "baptisteArno",
@ -11,7 +11,7 @@
},
"scripts": {
"deploy": "pnpm copy && pnpm commit",
"copy": "svn copy ./trunk ./tags/3.1.3",
"commit": "svn ci -m 'Update plugin metadata and readme'"
"copy": "svn copy ./trunk ./tags/3.1.4",
"commit": "svn ci -m 'Support for custom apiHost'"
}
}

View File

@ -5,7 +5,7 @@ Requires at least: 5.0
Tested up to: 6.0
License: GPL 2.0
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
Stable Tag: 3.1.3
Stable Tag: 3.1.4
== Description ==
Collect 4x more responses with conversational apps using Typebot.
@ -24,6 +24,9 @@ This plugin relies on Typebot which is a tool that allows you to create conversa
3. Activate your Typebot with the "Typebot" admin button located in the sidebar
== Changelog ==
= 3.1.4 =
* Support for apiHost field in shortcode
= 3.1.1 =
* Fix excluded pages when empty

View File

@ -80,6 +80,7 @@ class Typebot_Public
$lib_url = "https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0/dist/web.js";
$width = '100%';
$height = '500px';
$api_host = 'https://api.typebot.io';
if (array_key_exists('width', $attributes)) {
$width = sanitize_text_field($attributes['width']);
}
@ -89,6 +90,9 @@ class Typebot_Public
if (array_key_exists('typebot', $attributes)) {
$typebot = sanitize_text_field($attributes['typebot']);
}
if (array_key_exists('apiHost', $attributes)) {
$api_host = sanitize_text_field($attributes['apiHost']);
}
if (!$typebot) {
return;
}
@ -97,7 +101,7 @@ class Typebot_Public
$bot_initializer = '<script type="module">
import Typebot from "' . $lib_url . '"
Typebot.initStandard({ id: "' . $id . '", typebot: "' . $typebot . '", prefilledVariables: { typebotWpUser } });</script>';
Typebot.initStandard({ apiHost: "' . $api_host . '", id: "' . $id . '", typebot: "' . $typebot . '", prefilledVariables: { typebotWpUser } });</script>';
return '<typebot-standard id="' . $id . '" style="width: ' . $width . '; height: ' . $height . ';"></typebot-standard>' . $bot_initializer;
}

View File

@ -3,7 +3,7 @@
/**
* Plugin Name: Typebot
* Description: Convert more with conversational forms
* Version: 3.1.2
* Version: 3.1.4
* Author: Typebot
* Author URI: http://typebot.io/
* License: GPL-2.0+
@ -16,7 +16,7 @@ if (!defined('WPINC')) {
die();
}
define('TYPEBOT_VERSION', '3.1.2');
define('TYPEBOT_VERSION', '3.1.4');
function activate_typebot()
{