This library provides Elixir API wrapper for the Microsoft Bot Framework and handles authentication and token management.
API documentation is available at https://hexdocs.pm/ex_microsofbot
- Add
ex_microsoftbotto your list of dependencies inmix.exs:-
def deps do
[{:ex_microsoftbot, "~> 2.0.2"}]
end- Add the registered bot app id and app password in your config:-
config :ex_microsoftbot,
app_id: "BOT_APP_ID",
app_password: "BOT_APP_PASSWORD"- Start the
ex_microsoftbot:
def application do
[applications: [:ex_microsoftbot]]
endThe modules ExMicrosoftBot.Client.Attachments and ExMicrosoftBot.Client.Conversations contain the functions to call the corresponding API of Microsoft Bot Framework. For example:
alias ExMicrosoftBot.Client.Conversations
def reply(activity = %Activity{}) do
text = "Hello, world!"
resp_activity =
%Activity{
type: "message",
conversation: activity.conversation,
recipient: activity.from,
from: activity.recipient,
replyToId: activity.id,
text: text
}
Conversations.reply_to_activity(
activity.serviceUrl,
activity.conversation.id,
activity.id,
resp_activity
)
endIn addition to the required auth configs mentioned in Installation, there are a few more options available to customize this lib:
config :ex_microsoftbot
using_bot_emulator: false,
scope: "https://api.botframework.com/.default",
http_timeout: nilDefault false. Set this to true to disable the auth token manager, and instead use a fake auth token in all requests.
Default "https://api.botframework.com/.default". This sets the scope used when authorizing with the BotFramework.
In milliseconds, defaults to the underlying lib (currently HTTPotion)'s default. Change this to set the timeout for each request to the Bot Framework.