Skip to content

Instantly share code, notes, and snippets.

View petitroto's full-sized avatar

NAKAMURA Masayuki petitroto

View GitHub Profile

Keybase proof

I hereby claim:

  • I am petitroto on github.
  • I am nakmas (https://keybase.io/nakmas) on keybase.
  • I have a public key ASDRWsyL49D0_V3t6fRsR35LO2I9wmpAYtvBZQ0vt_rfowo

To claim this, I am signing this object:

@petitroto
petitroto / fix.sh
Created October 10, 2022 22:39
Un-quarantine the Botpress macOS binary to work on macOS 10.15 or later
#!/bin/sh
# Run this script in the same directory as the bp command
xattr -d com.apple.quarantine ./bp
xattr -d com.apple.quarantine ./bin/studio
xattr -d com.apple.quarantine ./bin/nlu
xattr -d com.apple.quarantine ./bin/messaging
xattr -d com.apple.quarantine ./bindings/darwin/all/node_sqlite3.node
xattr -d com.apple.quarantine ./bindings/darwin/all/fse.node
@petitroto
petitroto / 00_sendUrlToBrowser
Created August 24, 2022 21:08
BotpressのフックからURLをブラウザで開くサンプル
// 'before incoming middleware' hook
if (event.preview === 'foo') {
const data = {url: 'http://example.com'}
const event2Browser = bp.IO.Event({
type: 'data',
channel: 'web',
direction: 'outgoing',
target: event.target,
botId: event.botId,
@petitroto
petitroto / reset-session-trigger.js
Created March 6, 2022 22:16
Botpress Webchatを開くたびに新しい会話から始める方法
/**
* Webchatの×ボタン押下時にセッションを削除するフック
*/
const resetSession = async () => {
if (event.type === 'reset-session-trigger') {
const sessionId = bp.dialog.createId(event)
await bp.dialog.deleteSession(sessionId, event.botId)
event.setFlag(bp.IO.WellKnownFlags.SKIP_DIALOG_ENGINE, true)
}
}
@petitroto
petitroto / changeAvatar.js
Created March 6, 2022 08:22
Botpress Webchatのアバター画像を動的に変更する方法(v12.26.0以降に対応)
/**
* KVSに保存されたアバター画像URLを応答メッセージへ設定するフック
*/
const changeAvatar = async () => {
// KVSからアバター画像のURLを取得
const kvsForBot = bp.kvs.forBot(event.botId)
const key = kvsForBot.getUserStorageKey(event.target, 'avatarImage')
const avatarImage = await kvsForBot.get(key)
// メッセージのアバターを書き換え
#!/usr/bin/env bash
#
# 言語サーバーもローカルで同時起動するスクリプト
# for botpress-v12_23_2-darwin-x64
#
# 利用する言語モデルの設定(本番利用時は100を300にすべき)
DIM=100
BASE_URL=https://botpress-public.nyc3.digitaloceanspaces.com/embeddings/
FILE_BPE=bp.ja.bpe.model