Skip to content

Instantly share code, notes, and snippets.

@spasiu
spasiu / JwtTokenGenerator.cs
Last active July 10, 2024 19:32
Generate a Zendesk Messaging JWT in .Net and login the user on the client side.
using System;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.IdentityModel.Tokens;
using System.Text;
public class JwtTokenGenerator
{
public string CreateZendeskJwtToken(string zendeskSecret, string keyId, string userName, string userEmail, string externalId)
{
var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(zendeskSecret));
@spasiu
spasiu / jwtgen.cs
Created January 18, 2024 19:00
generate a JWT in C#
using System;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using Microsoft.IdentityModel.Tokens;
public class JwtTokenGenerator
{
public string CreateZendeskJwtToken(string zendeskSecret, string userId, string userName)
{
openapi: 3.0.0
info:
title: Your API
version: 1.0.0
servers:
- url: https://yourapi.com
security:
- BearerAuth: []
components:
securitySchemes:
const express = require('express');
const jwt = require('jsonwebtoken');
const app = express();
const PORT = 3000;
const SHARED_SECRET = '';
const ZENDESK_SUBDOMAIN = '';
app.get('/test', (req, res) => {
function getRandomNumber(cb) {
setTimeout(() => cb(random()), random());
}
function random() {
return Math.round(Math.random() * 1000);
}
// generate an array of 64 random numbers using the getRandomNumber function. Each elment in the array must be guaranteed unique.
@spasiu
spasiu / regex.txt
Last active November 9, 2021 20:34
regex to log function name in typescript
(export const (.*) = (\w|\s)*\((\n|\s|\w|:|,|<|>)*\):.*=> \{\n)
$1 console.log('$2')\n
@spasiu
spasiu / archiver.js
Created November 3, 2020 16:12
New Slack channel Archiver
'use strict';
const request = require('request')
const token = '<BotUserOAuthAccessToken>'
const paths = {
list: `https://slack.com/api/conversations.list?token=${token}&exclude_archived=true`,
archive: `https://slack.com/api/conversations.archive?token=${token}&channel=`,
join: `https://slack.com/api/conversations.join?token=${token}&channel=`
}
const log = tag => v => {
@spasiu
spasiu / switchboard_projects.md
Last active July 22, 2020 19:41
Switchboard Projects

Switchboard projects

Prerequisites

  • Node dev environment
  • Sunco v2 and Switchboard access

SunCo docs

@spasiu
spasiu / app.js
Last active July 15, 2020 15:42
switchboard bot
const axios = require('axios');
const express = require('express');
const bodyParser = require('body-parser');
const APP_ID = '';
const KEY_ID = '';
const SECRET = '';
const author = {
role: 'appMaker',
@spasiu
spasiu / get_convo_log_events.js
Created April 28, 2020 19:04
Get events for a particular conversation
/*
provide a unix timestamp in seconds
a conversation ID
and a count for number of calls to the logs API to make
results stored in global variable "results"
*/
const TIMESTAMP_SECONDS = '';
const CONVERSATION_ID = '';