Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(integrations): Adding Shopify Integration #12758

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
12453fd
Shopify first draft
bassamtantawi-botpress Aug 3, 2023
4d3fbc5
Prettier
bassamtantawi-botpress Aug 3, 2023
1e8e4a2
Merge branch 'master' into bt-shopify
bassamtantawi-botpress Aug 3, 2023
01ce3f8
Merge branch 'master' into bt-shopify
bassamtantawi-botpress Aug 4, 2023
27c402b
Review comments & the automated checks fixes.
bassamtantawi-botpress Aug 4, 2023
a96d268
Merge branch 'bt-shopify' of https://github.com/botpress/botpress int…
bassamtantawi-botpress Aug 4, 2023
641322c
prettier
bassamtantawi-botpress Aug 4, 2023
5911d96
fixes for schema and lint
bassamtantawi-botpress Aug 4, 2023
a7a2ad7
prettier
bassamtantawi-botpress Aug 4, 2023
cd89fcb
Merge branch 'master' into bt-shopify
bassamtantawi-botpress Aug 7, 2023
f6387d9
Updates
bassamtantawi-botpress Aug 7, 2023
b9ef614
fixing some of the errors
bassamtantawi-botpress Aug 8, 2023
d997809
adding botpresshub to the package
bassamtantawi-botpress Aug 8, 2023
d75e369
for checks
bassamtantawi-botpress Aug 8, 2023
5dae2d9
Merge branch 'master' into bt-shopify
bassamtantawi-botpress Aug 8, 2023
7e1f2e9
Update integrations/shopify/src/setup/register.ts
bassamtantawi-botpress Aug 9, 2023
a619a65
Update integrations/shopify/src/setup/unregister.ts
bassamtantawi-botpress Aug 9, 2023
2ddc3c7
Update integrations/shopify/src/setup/unregister.ts
bassamtantawi-botpress Aug 9, 2023
34dcea7
Merge branch 'master' into bt-shopify
bassamtantawi-botpress Aug 9, 2023
e932a4f
Review comments
bassamtantawi-botpress Aug 9, 2023
4c5b018
Merge branch 'bt-shopify' of https://github.com/botpress/botpress int…
bassamtantawi-botpress Aug 9, 2023
4f0a853
review comments
bassamtantawi-botpress Aug 9, 2023
975fe7c
fix
bassamtantawi-botpress Aug 9, 2023
6f5db53
prettier
bassamtantawi-botpress Aug 9, 2023
1f883b6
adding types
bassamtantawi-botpress Aug 9, 2023
0a8742f
lint check
bassamtantawi-botpress Aug 9, 2023
bbc3fff
fix for lint
bassamtantawi-botpress Aug 9, 2023
52844ad
fix
bassamtantawi-botpress Aug 9, 2023
8a7f8cc
Merge branch 'master' into bt-shopify
bassamtantawi-botpress Aug 9, 2023
9122b66
Merge branch 'master' into bt-shopify
bassamtantawi-botpress Aug 10, 2023
03445a3
Merge branch 'master' into bt-shopify
bassamtantawi-botpress Aug 10, 2023
ed5cedb
Updates for the states and a fix
bassamtantawi-botpress Aug 10, 2023
bdd8802
Merge branch 'bt-shopify' of https://github.com/botpress/botpress int…
bassamtantawi-botpress Aug 10, 2023
15e22ab
Merge branch 'master' into bt-shopify
bassamtantawi-botpress Aug 15, 2023
3ba6899
Merge branch 'master' into bt-shopify
bassamtantawi-botpress Aug 16, 2023
f7d1e37
updating the scripts
bassamtantawi-botpress Aug 16, 2023
62bf551
Merge branch 'bt-shopify' of https://github.com/botpress/botpress int…
bassamtantawi-botpress Aug 16, 2023
a96b027
Merge branch 'master' into bt-shopify
bassamtantawi-botpress Aug 17, 2023
962ae4e
Merge branch 'master' into bt-shopify
michaelmass Aug 23, 2023
04baa7e
update
michaelmass Aug 23, 2023
47b466c
update
michaelmass Aug 23, 2023
d901e51
update
michaelmass Aug 23, 2023
26d449b
update
michaelmass Aug 23, 2023
e4ec8ce
update
michaelmass Aug 23, 2023
26c7f9e
update
michaelmass Aug 23, 2023
93df815
update
michaelmass Aug 23, 2023
babcd04
update
michaelmass Aug 23, 2023
227e616
update
michaelmass Aug 23, 2023
931df59
Removing the state, counting on the "get webhooks"
bassamtantawi-botpress Aug 28, 2023
5271885
Merge branch 'master' into bt-shopify
michaelmass Aug 29, 2023
685e2c5
Merge branch 'master' into bt-shopify
bassamtantawi-botpress Aug 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions integrations/shopify/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.botpress
5 changes: 5 additions & 0 deletions integrations/shopify/.sentryclirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[defaults]
project=integration-shopify

[auth]
dsn=https://58077d91efaa7f20094ecb7e872bc23b@o363631.ingest.sentry.io/4505755730968576
45 changes: 45 additions & 0 deletions integrations/shopify/hub.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
This integration enables you to connect your Botpress chatbot with Shopify, a leading e-commerce platform. With this integration, you can facilitate seamless interactions related to store operations directly from your chatbot.

To effectively use the integration, you'll need to provide your Shopify store name (as seen in the browser/URL) and the access token generated after adding our App to your shop.

For comprehensive instructions on setting up and utilizing the Botpress Shopify integration, please consult our main documentation.

## Prerequisites

Before enabling the Botpress Shopify Integration, ensure you have:

1. A Botpress cloud account.
2. Access to a Shopify store admin panel.
3. An access token, generated after adding our App to your Shopify store.

## Configuration Setup

To set up the Shopify integration in Botpress, the following configurations are required:

1. **Shop/Store Name**: Extracted from the browser/URL when accessing your Shopify store. For instance, if the URL to your store admin is \`https://admin.shopify.com/store/botpress-test-store\`, then the shop name you'll enter is \`botpress-test-store\`.
2. **Admin API access token**: This token is essential for allowing Botpress to communicate with your Shopify store. It can be located within the app settings under the 'API credentials' section in your Shopify admin panel.

## Enable Integration

To activate the Shopify integration in Botpress:

1. Access the Botpress admin dashboard.
2. Go to the "Integrations" tab.
3. Search for the Shopify integration and select "Enable" or "Configure."
4. Input the required Shop/Store Name and Admin API access token.
5. Save your configurations.

## Usage

After enabling the integration, your Botpress chatbot can seamlessly communicate with Shopify, aiding in tasks like product queries, order updates, and more. Specific built-in actions and more detailed usage instructions will be found in our core documentation.

## Limitations

1. Ensure you always have the correct and latest Admin API access token for accurate integration functionality.
2. There may be rate limits applied by Shopify's API.

## Contributing

Your contributions are valued! Feel free to submit any issues or pull requests.

Relish the smooth e-commerce operations integration between Botpress and Shopify!
12 changes: 12 additions & 0 deletions integrations/shopify/icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions integrations/shopify/integration.definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { IntegrationDefinition } from '@botpress/sdk'
import { sentry as sentryHelpers } from '@botpress/sdk-addons'
import { INTEGRATION_NAME } from './src/const'
import { actions } from './src/definitions/actions'
import { configuration } from './src/definitions/configuration'
import { events } from './src/definitions/events'
import { states } from './src/definitions/states'

export default new IntegrationDefinition({
name: INTEGRATION_NAME,
title: 'Shopify',
description: 'This integration allows your bot to interact with Shopify.',
version: '0.2.0',
icon: 'icon.svg',
readme: 'hub.md',
configuration,
actions,
states,
events,
secrets: [...sentryHelpers.COMMON_SECRET_NAMES],
})
30 changes: 30 additions & 0 deletions integrations/shopify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@botpresshub/shopify",
"scripts": {
"start": "bp serve",
"build": "bp build",
"deploy": "bp deploy",
"type:check": "tsc --noEmit",
"test": "echo \"Tests not implemented yet.\""
},
"keywords": [],
"private": true,
"author": "",
"license": "MIT",
"dependencies": {
"@botpress/client": "workspace:*",
"@botpress/sdk": "workspace:*",
"@botpress/sdk-addons": "workspace:*",
"axios": "^1.4.0",
"zod": "^3.21.4"
},
"devDependencies": {
"@botpress/cli": "workspace:*",
"@sentry/cli": "^2.18.1",
"@types/node": "^18.11.17",
"esbuild": "^0.15.18",
"nodemon": "^2.0.20",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
}
}
37 changes: 37 additions & 0 deletions integrations/shopify/src/actions/get-customerOrders.ts
bassamtantawi-botpress marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { RuntimeError } from '@botpress/client'
import axios from 'axios'
import qs from 'querystring'
import { SHOPIFY_API_VERSION } from '../const'
import { IntegrationProps } from '.botpress'

type GetCustomerOrders = IntegrationProps['actions']['getCustomerOrders']

export const getCustomerOrders: GetCustomerOrders = async ({ ctx, input, logger }) => {
const { customer_id, status } = input
const filters = qs.stringify({ customer_id, status })

const axiosConfig = {
baseURL: `https://${ctx.configuration.shopName}.myshopify.com`,
headers: {
'X-Shopify-Access-Token': ctx.configuration.access_token,
},
}

try {
const response = await axios.get(`/admin/api/${SHOPIFY_API_VERSION}/orders.json?${filters}`, axiosConfig)

const customerOrdersList = response.data.orders

logger
.forBot()
.info(
`Ran 'Get Customer Orders List' and found ${customerOrdersList.length} customer orders matching criteria ${filters}`
)

return { customerOrdersList }
} catch (e) {
const errorMsg = `'Get Customer Orders List' exception ${JSON.stringify(e)}`
logger.forBot().error(errorMsg)
throw new RuntimeError(errorMsg)
}
}
35 changes: 35 additions & 0 deletions integrations/shopify/src/actions/get-customers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { RuntimeError } from '@botpress/client'
import axios from 'axios'
import qs from 'querystring'
import { SHOPIFY_API_VERSION } from '../const'
import { IntegrationProps } from '.botpress'

type GetCustomers = IntegrationProps['actions']['getCustomers']

export const getCustomers: GetCustomers = async ({ ctx, input, logger }) => {
const { ids, limit } = input
const filters = qs.stringify({ ids, limit })

const axiosConfig = {
baseURL: `https://${ctx.configuration.shopName}.myshopify.com`,
headers: {
'X-Shopify-Access-Token': ctx.configuration.access_token,
},
}

try {
const response = await axios.get(`/admin/api/${SHOPIFY_API_VERSION}/customers.json?${filters}`, axiosConfig)

const customersList = response.data.customers

logger
.forBot()
.info(`Ran 'Get Customers List' and found ${customersList.length} customers matching criteria ${filters}`)

return { customersList }
} catch (e) {
const errorMsg = `'Get Customers List' exception ${JSON.stringify(e)}`
logger.forBot().error(errorMsg)
throw new RuntimeError(errorMsg)
}
}
37 changes: 37 additions & 0 deletions integrations/shopify/src/actions/get-productVariant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { RuntimeError } from '@botpress/client'
import axios from 'axios'
import qs from 'querystring'
import { SHOPIFY_API_VERSION } from '../const'
import { IntegrationProps } from '.botpress'

type GetProductVariants = IntegrationProps['actions']['getProductVariants']

export const getProductVariants: GetProductVariants = async ({ ctx, input, logger }) => {
const { product_id, limit } = input
const filters = qs.stringify({ product_id, limit })

const axiosConfig = {
baseURL: `https://${ctx.configuration.shopName}.myshopify.com`,
headers: {
'X-Shopify-Access-Token': ctx.configuration.access_token,
},
}

try {
const response = await axios.get(`/admin/api/${SHOPIFY_API_VERSION}/variants.json?${filters}`, axiosConfig)

const productVariantsList = response.data.variants

logger
.forBot()
.info(
`Ran 'Get Product Variants List' and found ${productVariantsList.length} product variants matching criteria ${filters}`
)

return { productVariantsList }
} catch (e) {
const errorMsg = `'Get Product Variants List' exception ${JSON.stringify(e)}`
logger.forBot().error(errorMsg)
throw new RuntimeError(errorMsg)
}
}
35 changes: 35 additions & 0 deletions integrations/shopify/src/actions/get-products.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { RuntimeError } from '@botpress/client'
import axios from 'axios'
import qs from 'querystring'
import { SHOPIFY_API_VERSION } from '../const'
import { IntegrationProps } from '.botpress'

type GetProductVariants = IntegrationProps['actions']['getProducts']

export const getProducts: GetProductVariants = async ({ ctx, input, logger }) => {
const { ids, limit, product_type, title } = input
const filters = qs.stringify({ ids, limit, product_type, title })

const axiosConfig = {
baseURL: `https://${ctx.configuration.shopName}.myshopify.com`,
headers: {
'X-Shopify-Access-Token': ctx.configuration.access_token,
},
}

try {
const response = await axios.get(`/admin/api/${SHOPIFY_API_VERSION}/products.json?${filters}`, axiosConfig)

const productsList = response.data.products

logger
.forBot()
.info(`Ran 'Get Products List' and found ${productsList.length} products matching criteria ${filters}`)

return { productsList }
} catch (e) {
const errorMsg = `'Get Products List' exception ${JSON.stringify(e)}`
logger.forBot().error(errorMsg)
throw new RuntimeError(errorMsg)
}
}
7 changes: 7 additions & 0 deletions integrations/shopify/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import '@botpress/client'
import { getCustomerOrders } from './get-customerOrders'
import { getCustomers } from './get-customers'
import { getProducts } from './get-products'
import { getProductVariants } from './get-productVariant'

export default { getProducts, getProductVariants, getCustomers, getCustomerOrders }
3 changes: 3 additions & 0 deletions integrations/shopify/src/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const INTEGRATION_NAME = 'shopify'
export const SHOPIFY_API_VERSION = '2023-07'
export const ARR_OF_EVENTS = ['orders/create', 'orders/cancelled', 'customers/create']