Make Watson Assistant send messages to your Discord Server
Prerequisites
- 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).
Activate Webhooks in Discord
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.
Set up your cloud function
Create cloud function
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.
Test cloud function
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.
Enable as Web Action
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.
Set up your Assistant
Set up Watson Assistant
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.
Create your own Skill
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.
Enable Webhooks
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.
Test your assistant
Now you can click on the Try it
button and test whether the assistant is working correctly.