Created
March 6, 2022 08:22
-
-
Save petitroto/f6bb4dbd22489200f32e6e141069cb8b to your computer and use it in GitHub Desktop.
Botpress Webchatのアバター画像を動的に変更する方法(v12.26.0以降に対応)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* アバター画像の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