Skip to content

Instantly share code, notes, and snippets.

@isaidspaghetti
isaidspaghetti / .env.extension
Created July 17, 2020 21:04
dotenv for hubspot stream apis
//backend/.env.example
NODE_ENV=development
PORT=8080
STREAM_API_KEY=your stream API key goes here
STREAM_API_SECRET=your stream API secret goes here
HUBSPOT_API_KEY=your Hubspot API key goes here
@isaidspaghetti
isaidspaghetti / App1.js
Created July 17, 2020 21:05
Frontend React Registration Chat Stream
//frontend/src/App.js:7
function App() {
const [email, setEmail] = useState('');
const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');
//...
return (
<div className="App container">
<form className="card" onSubmit={register}>
<label>First Name</label>
@isaidspaghetti
isaidspaghetti / App2.js
Created July 17, 2020 21:12
handle form submit stream registration
//frontend/src/App.js:15
const register = async (e) => {
try {
e.preventDefault();
var response = await fetch('http://localhost:8080/registrations', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
@isaidspaghetti
isaidspaghetti / api1.js
Created July 17, 2020 21:46
Cinfiguring backend api
//backend/routes/index.js:1
const express = require('express');
const router = express.Router();
const StreamChat = require('stream-chat');
const Hubspot = require('hubspot');
require('dotenv').config();
const apiKey = process.env.STREAM_API_KEY;
const apiSecret = process.env.STREAM_API_SECRET;
@isaidspaghetti
isaidspaghetti / api2.js
Created July 17, 2020 21:47
backend router handler
//backend/routes/index.js:46
router.post('/registrations', async (req, res, next) => {
try {
await createHubspotContact(firstName, lastName)
const client = new StreamChat.StreamChat(apiKey, apiSecret);
[customer, supporter] = createUsers(firstName, lastName)
await client.upsertUsers([
@isaidspaghetti
isaidspaghetti / api3.js
Created July 17, 2020 21:48
create hubspot contact
//backend/routes/index.js:10
async function createHubspotContact(firstName, lastName) {
const hubspot = new Hubspot({
apiKey: process.env.HUBSPOT_API_KEY,
checkLimit: false
})
const contactObj = {
properties: [
{ property: 'firstname', value: firstName },
@isaidspaghetti
isaidspaghetti / api4.js
Created July 17, 2020 21:49
create users stream
function createUsers(firstName, lastName) {
const customer = {
id: `${firstName}-${lastName}`.toLowerCase(),
name: firstName,
role: 'user',
};
const supporter = {
id: 'adminId',
name: 'unique-admin-name',
@isaidspaghetti
isaidspaghetti / App3.js
Created July 17, 2020 21:50
Render react Stream Chat
//frontend/App.js:7
function App() {
//...
const [chatClient, setChatClient] = useState(null);
const [channel, setChannel] = useState(null);
const register = async (e) => {
try {
e.preventDefault();
var response = await fetch('http://localhost:8080/registrations', {
@isaidspaghetti
isaidspaghetti / App4.js
Created July 17, 2020 21:51
React Stream imports
//frontend/App.js
import { Chat, Channel, ChannelHeader, MessageInput, MessageList, Thread, Window, } from 'stream-chat-react';
import { StreamChat } from 'stream-chat';
import 'stream-chat-react/dist/css/index.css'
//backend/.env
NODE_ENV=development
PORT=8080
STREAM_API_KEY= your Stream API key here
STREAM_API_SECRET= your Stream API secret here
HUBSPOT_API_KEY=your HubSpot API key here