Skip to content

Instantly share code, notes, and snippets.

@petitroto
Created March 6, 2022 08:22
Show Gist options
  • Save petitroto/f6bb4dbd22489200f32e6e141069cb8b to your computer and use it in GitHub Desktop.
Save petitroto/f6bb4dbd22489200f32e6e141069cb8b to your computer and use it in GitHub Desktop.
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)
// メッセージのアバターを書き換え
Object.assign(event.payload, {
channel: { web: { avatarUrl: avatarImage } }
})
}
return changeAvatar()
/**
* アバター画像のURLをKVSへ保存するアクション
* @title アバター画像設定
* @category Custom
* @author nakmas
* @param {string} avatarImage - アバター画像のURL
*/
const setAvatarImage = async avatarImage => {
const kvsForBot = bp.kvs.forBot(event.botId)
const key = kvsForBot.getUserStorageKey(event.target, 'avatarImage')
await kvsForBot.set(key, avatarImage)
}
return setAvatarImage(args.avatarImage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment