MS Bot Framework application to public account, botframework
1. Download the SDK of the Bot Framework
First, download the SDK of the Bot Framework. We recommend that you download the Bot Application template of the Visual Studio of the Bot Framework.
For the downloaded template (do not decompress it), place it directly under C: \ Users \ your username \ Documents \ Visual Studio 2015 \ Templates \ ProjectTemplates \ Visual C, in this way, you can see the template with the Bot Application in C.
2. Create a Bot Application
Click create and Publish directly.
Publish to local IIS and Configure Ports, such as 20080
3. Use the ngrok tool to expose the local site to the Internet
Because the Internet https link is required when registering a bot, we need to first cast BotTest to the Internet. You can skip this step if you have an ssl certificate on the Internet (not a self-signed certificate ).
1. First visit the official website, https://ngrok.com/register an account (after registration can get your own account secret key for subsequent binding operations ).
2. After registration, you can view your own key information and a download link on the redirected page without paying attention to the payment module.
Hosts file. The prompt is as follows. The correct operation is to extract the package to ngrok. Then, place the decompressed folder to the desired folder. For example, place it in the D: \ ngrok directory.
Open cmd
Enter d: Enter
Input cd: ngrok
Enter the Install your authtoken
Finally, set the corresponding port number, for example, 20080 ngrok http 20080.
Then the operation is completed.
4. register an application on the Bot Framework website
When registering, you must have a Microsoft account to log on and then agree to the authorization. On the page, click Register a bot to start registration:
"Name": the Name of your bot.
"Bot Handle": Actually your Bot id.
"Description": the Description of your Bot. It will be displayed on the homepage after your publish.
Endpoint is the address of your backend service: https: // your server address/api/messages (default Interface of template we just released)
You need to click "Create Microsoft App ID and password" to Create the App ID and Password (note,Remember to write down this app password, Only once)
Some of the following mandatory options can be entered at will.
Click Save.
Update the webconfig of a program
Click Get bot embed codes under Channels
Replace the obtained code into the default.htm body.
Visit this page:
At this point, the robot is partially completed.
Because the web site generated by ngrok is invalid after a period of time or is not used, it needs to be generated again and then configured to the bot.
V. LUIS Service
Log on to: https://www.luis.ai/, the portal of the Language Understanding service. If you have not yet registered, use the live id to register the following.
Click "new App" to create an app.
After the application is created, click "Edit" to Edit the application.
Let's first look at the tab on the left of the following to see Intents, Entities, Pre-built Entities ....
Intents: indicates the intention. For example, if we want to provide the book query service, we will create an Intent for "querying books.
Entities: instances. For example, when querying a book, you need information such as the title, publisher, and price. You need to extract the information in your language. These are examples in this sentence, let's create a "book" instance.
Pre-built Entities: This is a preset instance, such as time and number. I added a datetime preset instance.
Regex Features: Regular Expression, which can match the corresponding fields, such as flight number.
Phrase List Features: fixed phrases that can be directly identified, such as known information such as airline names
Create a question, mark the title as a book, and click submit
Click Train in the lower left corner.
After training, click Publish.
Integrate the LUIS service in the Bot. For more information, seeMin zepeng's blog. I made some adjustments, but the principle is the same.
6. Use the botframework-emulator Tool
This tool can be downloaded to the https://emulator.botframework.com.
With this tool, you can debug code and bypass Step 4 to register an application on the Bot Framework website. However, the [BotAuthentication] On MessagesController must be deregistered first.
To download and open the SDK, you must first perform app setting. Configure the local ngrok path.
Then, enter the local path link to perform the operation.
The tool on the right also automatically records logs. If an exception occurs, you can view the Details in the Details section.
VII.Use Http Request to Request
Getting the Bot Framework returns is detailed in the http://www.cnblogs.com/sonic1abc/p/5941442.html.
In addition, if you neither have https nor want to use a proxy, you can bypass the Bot Framework to directly request Luis and then customize the data returned by Luis:
System. Net. WebRequest wrq = System. Net. WebRequest. Create (uri );
Wrq. Headers. Add ("Ocp-Apim-subkeys-Key", luis_Key );
Wrq. Method = "GET ";
ServicePointManager. SecurityProtocol = SecurityProtocolType. Tls; // replace SSL3 with TLS.
System. NetWebResponse wrp = wrq. GetResponse ();
System. IO. StreamReader sr = new System. IO. StreamReader (wrp. GetResponseStream (), System. Text. Encoding. GetEncoding ("UTF-8 "));
StrResult = sr. ReadToEnd ();
Lusi ro = JsonHelper. JsonDeserialize <Lusi> (strResult );
The information obtained after deserialization is the same as that obtained by the Luis website request.
After processing the information, you can call the api to return it, which can complete the above artificial intelligence.
Public class MessageBiz: BaseBiz
{
Public SendResponse Send <T> (T request)
{
String strJson = JsonConvert. SerializeObject (request );
// _ SendLog. WriteLog ("new:" + strJson );
Base. url = "https://qyapi.weixin.qq.com/cgi-bin/message/send? Access_token = "+ TokenBiz. GetAccessToken (str_corpid, str_corpsecret );
Base. para = strJson;
Base. method = "POST ";
Base. needAccessToken = true;
Var res = base. GetUrlReturn <SendResponse> ();
Return res;
}
}
Because I am an enterprise number, so call the enterprise number service, interface description can see: http://qydev.weixin.qq.com/wiki/index.php? Title = % E5 % 8F % 91% E9 % 80% E6 % 8E % A5 % E5 % 8F % A3 % E8 % AF % B4 % E6 % 81% 8E. The public account principle is the same, and the public account interface is another implementation.
Finally, let's take a look at the effect.
References:
Http://www.cnblogs.com/rocsheh/p/5846009.html
Http://blog.csdn.net/xxdddail/article/details/51190754
Http://blog.csdn.net/gebitan505/article/details/39497779
Http://www.cnblogs.com/sonic1abc/p/5941442.html