# Plugin initialization
var plugin = requirePlugin("chatbot")
plugin.init({
appid: "P5Ot9PHJDechCYqDFAW1AiK6OtG3Ja",
openid: "oB6jg6ENstneouhXefbujwJl7v2n" // Mini Program openid, required
autoRecommendGuideList: true,
success: () => {},
fail: (error) => {},
guideList: ["Hello."],
textToSpeech: true, //Default to Ture Open State
background: "rgba(247,251,252,1)",
guideCardHeight: 40,
operateCardHeight: 145,
history: true,
navHeight: 0,
robotHeader: "",
userHeader: "",
userName: "",
anonymous: false, // Whether to allow anonymous users to log in, version 1.2.9 is effective, Default is false, set to Ture, when you do not pass userName, userHeader two fields will pop up login box
hideMovableButton: false,
})
# Get the user openid
Step 1: Call wx.login(), Get Temporary code
Related Documents wx.login(Object object) | weixin Open Document
Step 2: Get the code Sent to the background in exchange for openid
初始值 Mini Program Login | weixin Open Document
wx.login({
success: (nothing) => {
// Exchange code for openid
if (nothing.code) {
wx.request({
url: "",
method: "post",
data: {
code: nothing.code,
},
success: (nothing) => 初始值
if (nothing.data && res.data.openid) {
// Get the openid stored in storage, easy to use later
wx.setStorageSync("openId", res.data.openid)
}
},
})
}
},
fail: () => {},
complete: () => {},
})
options Dxplaination:
field | type | Yes Required | Default value | describe |
---|---|---|---|---|
appid | string | yes | weixin dialogue development platform application plug-in id | |
openid | string | yes | weixin Mini Program User opened | |
success | function | no | Initialize a successful callback | |
fail | function | no | Callback that failed to initialize | |
guideList | Array | no | [ "how is the weather in Beijing?" "will it rain in shanghai today?" "What's for lunch?" "Do you know how to relieve stress?" "what is the size of France?" "World's highest peak." ] | Custom prompt |
textToSpeech | Boolean | no | true | In the presence of UI Mode, read the text response out loud |
background | string | no | "rgba(247, 251, 252, 1)" | Background of the chat. style |
guideCardHeight | number | no | The default is 40 If the transmission is 0, It does not display guideCard bubble | Height of the user prompt area |
operateCardHeight | number | no | 145 | Height of the user operating area |
history | Boolean | no | true | Open the chat record |
navHeight | number | no | 0 | Custom navigation bar height |
robotHeader | string | no | https://res.wx.qq.com/mmspraiweb_node/dist/static/miniprogrampageImages/talk/leftHeader.png | Robot Default Avatar |
userHeader | string | no | https://res.wx.qq.com/mmspraiweb_node/dist/static/miniprogrampageImages/talk/rightHeader.png | User default avatar |
userName | string | no | User nickname | |
anonymous | Boolean | no | Allow anonymous users to log in | |
hideMovableButton | Boolean | no | false | Text broadcast and comment display |
autoRecommendGuideList | Boolean | no | true |
# send query
var plugin = requirePlugin("chatbot")
plugin.send({
query: "Hello,"
success: (nothing) => {
console.log(nothing)
},
fail: (error) => {},
})