Skip to content

Instantly share code, notes, and snippets.

View benbrown's full-sized avatar
👹

Ben Brown benbrown

👹
View GitHub Profile
@benbrown
benbrown / fiction.quest.timetravel
Last active May 18, 2023 00:17
Transcript of an imaginary time travel journey featuring Max Headroom, Theora Jones and Rufus from Bill and Ted.
This is a transcript of a machine-generated story
that took place in fiction.quest. The lines starting
with > were my commands. The rest are the hallucinations
of a machine that was raised on our popular culture.
https://fiction.quest
> Rufus, let's take Max on a time travel adventure
Rufus grins widely at Zeb, his eyes lighting up with
@benbrown
benbrown / chat.js
Created April 26, 2023 14:50
Minimal GPT chat experience that runs on the command line
// install these libs, set OPENAI_API_KEY, and put your baseline prompt in prompt.txt.
require('dotenv').config()
const { Configuration, OpenAIApi } = require("openai");
const wordwrapjs = require('wordwrapjs');
const fs = require('fs');
const prompt = require('prompt-sync')({sigint: true});
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
@benbrown
benbrown / multibot.md
Last active February 11, 2021 16:02
How to test the multibot template
@benbrown
benbrown / botframework-composer-packages.json
Last active October 27, 2020 15:58
a list of the promoted packages displayed in bot framework composer
[
{
"name": "benbrown/grammarHelperLG",
"version": "",
"source": "npm",
"language" :"js",
"repository": "https://github.com/benbrown/grammarHelperLG",
"authors": ["Ben Brown <benbrown@gmail.com>"],
"category": "Community Packages",
"description": "A collection of LG rules to help form proper sentences out of dynamic data"

How to build a bot framework compatible adapter

Bot Framework uses a concept called "adapters" to create an interface between external messaging platforms and the bot logic. Adapters are responsible for passing messages and events back and forth between the bot and users, and translating them between their external and internal forms.

There are many open source adapters available (for Node, for C#), but there are many messaging platforms still unsupported. The code for these adapters provides a good template for creating a new one.

The Azure Bot Service channel system can be thought of as a meta-adapter: in this case, the translation is done in the cloud by the service, and

What does an adapter do?

@benbrown
benbrown / using-lg.md
Last active May 6, 2019 21:56
use the new botbuilder-lg system to generate bot replies with Botkit

Switch npm to pull from the Bot Framework nightly build to install botbuilder-lg's preview release:

npm config set registry https://botbuilder.myget.org/F/botbuilder-declarative/npm/
npm install --save botbuilder-lg@4.5.0

Put this code in a Botkit skill:

@benbrown
benbrown / botinspector.js
Last active May 6, 2019 20:13
enable bot framework emulator "bot inspector" mode in botkit v4+
/**
* This module if installed into a botkit v4+ app will enable "Bot Inspector" mode in Bot Framework Emulator.
* Put it in features/botinspector.js inside your fresh Botkit app.
* This allows you to connect to the bot app running locally with emulator to inspect messages
* as they come and go to the messaging platform.
* Read more here:
* https://github.com/Microsoft/botframework/blob/master/README.md#bot-inspector-new---preview
*/
// import botbuilder 4.4 library
const { InspectionMiddleware, InspectionState, BotFrameworkAdapter } = require('botbuilder')
var schedule = require('node-schedule');
// channel/group ID fields for the places you want to send messages
var groupChannels = ['G6BKKTVPG', 'C6WHTV57V'];
// your slack team's id, needed to spawn a bot
var team_id = 'T123123';
// this can probably be a FAKE user id, just required as part of startConversation
var user_id = 'U123';
@benbrown
benbrown / botkit-anywhere-trigger.js
Created June 25, 2018 21:05
How to trigger a script in to start as soon as the page loads with Botkit Anywhere
Botkit.on('connected', function() {
Botkit.triggerScript('script','thread');
});
var user_id = 123;
app.controller('chat', ['$scope',function($scope, $cookies) {
var socket;
$scope.reconnect_count = 0;
$scope.reconnect_timeout = 3000;
$scope.max_reconnect = 5;