In this workshop we are going to connect Watson Assistant to a Discord Webhook, which allows us to send messages from our Assistant to a Discord textchannel.
In this workshop we are going to:
- Set up a Discord webhook
- Set up an IBM cloud function to call our webhook
- Set up our Assistant, and connect it to the cloud function
- Sign up for an IBM Cloud account.
- Fill in the required information and press the „Create Account“ button.
- After you submit your registration, you will receive an e-mail from the IBM Cloud team with details about your account. In this e-mail, you will need to click the link provided to confirm your registration.
- Now you should be able to login to your new IBM Cloud account ;-)
- Create a Discord account, as well your own Discord server (both are free of charge).
We want to enable webhooks in our Discord server's settings, which will be used by Watson Assistant
to send messages.
Note: Discord does not require any additional Authentification, which means that anyone who has the URL can use the Webhook. Ensure that only you, and people you trust have access to it.
We could use the Discord webhook directly, but since Discord sends us an empty response on success, our assistant wouldn't be able to verify, wether the message was sent correctly or not.
We want to set up a cloud function, which Watson Assistant will be able to access. To do that, you need to go to your IBM Cloud Dashboard
, and select Functions
.
Alternatively you can click here to access the IBM Cloud functions.
Now you can create a new Action. Give it a sensible name, select python
as your runtime, and click create.
Paste in the code that can be found here, change the value of discordurl
to your URL, and save your changes.
If you want to test it, you can click on Invoke with parameter
, paste in the input below, click apply
, and press Invoke
.
{
"content" : "this is a test message sent by your cloud function"
}
If the message was sent successfully, the result should look like this.
Now we need to create an endpoint, which will be used by Watson Assistant
to invoce your function.
On the left side, click Endpoints
and check the box called Enable as Web Action
. Press save, and copy the URL.
Go back to your Dashboard, and type Watson Assistant
into the search bar. If you already have a Watson Assistant
service you can use it, otherwise you can create a free lite version either by clicking Watson Assistant
under the Catalog Results
Section or following this link.
Afterwards launch your Watson Assistant
Service, and look for Skills
on the left.
If you can't find it, click on the profile icon in the upper right corner, and click
Switch to classic experience
.
Create a new skill, select Dialog skill
and click next. Select Upload skill
and provide the skill-Connect-to-Discord.json
file.
Before you can test your assistant, you need to provide the cloud funtion's URL.
Click on Options->Webhooks, paste in the URL, and ADD A .json
AT THE END.
We could use Discord's webhook link direcly, without adding a .json, and it would send the message as well. However, Discord doesn't return anything (that Watson Assistant can understand), which would prevent us from informing the user of our assistant, that the message was sent correctly.
Now you can click on the Try it
button and test whether the assistant is working correctly.