-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from finos/spring-bot-develop
9.0.0.BETA Release
- Loading branch information
Showing
25 changed files
with
594 additions
and
514 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
|
||
|
@@ -14,11 +13,8 @@ | |
import org.finos.springbot.teams.content.TeamsMultiwayChat; | ||
import org.finos.springbot.teams.content.TeamsUser; | ||
import org.finos.springbot.teams.turns.CurrentTurnContext; | ||
import org.finos.springbot.workflow.content.Addressable; | ||
import org.finos.springbot.workflow.content.Chat; | ||
import org.finos.springbot.workflow.content.User; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.microsoft.bot.builder.BotFrameworkAdapter; | ||
import com.microsoft.bot.builder.TurnContext; | ||
|
@@ -33,15 +29,22 @@ | |
import com.microsoft.bot.schema.ConversationReference; | ||
import com.microsoft.bot.schema.ResourceResponse; | ||
|
||
public class TeamsConversationsImpl implements TeamsConversations { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(TeamsConversationsImpl.class); | ||
/** | ||
* Teams doesn't seem to support lookup of the list of conversations a bot is | ||
* involved in, which makes it impossible to write getAllAddressables(). | ||
* | ||
* This is left as a problem for the subclass ;) | ||
* | ||
* @author [email protected] | ||
* | ||
*/ | ||
public abstract class AbstractTeamsConversations implements TeamsConversations { | ||
|
||
private MicrosoftAppCredentials mac; | ||
private BotFrameworkAdapter bfa; | ||
private ChannelAccount botAccount; | ||
|
||
public TeamsConversationsImpl(BotFrameworkAdapter bfa, MicrosoftAppCredentials mac, ChannelAccount botAccount) { | ||
public AbstractTeamsConversations(BotFrameworkAdapter bfa, MicrosoftAppCredentials mac, ChannelAccount botAccount) { | ||
super(); | ||
this.mac = mac; | ||
this.bfa = bfa; | ||
|
@@ -65,29 +68,6 @@ public boolean isSupported(User u) { | |
return u instanceof TeamsUser; | ||
} | ||
|
||
@Override | ||
public Set<Addressable> getAllAddressables() { | ||
try { | ||
return getConversations().getConversations().get().getConversations().stream() | ||
.map(c -> new TeamsMultiwayChat(c.getId(), "")) | ||
.collect(Collectors.toSet()); | ||
} catch (Exception e) { | ||
throw new TeamsException("Couldn't do getAllAddressables", e); | ||
} | ||
} | ||
|
||
@Override | ||
public Set<TeamsChat> getAllChats() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public TeamsChat getExistingChat(String name) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public TeamsChat ensureChat(TeamsChat r, List<TeamsUser> users, Map<String, Object> meta) { | ||
// TODO Auto-generated method stub | ||
|
@@ -237,9 +217,12 @@ private TurnContext getWorkingTurnContext(TeamsAddressable ta) { | |
|
||
public CompletableFuture<ResourceResponse> handleActivity(Activity activity, TeamsAddressable to) { | ||
TurnContext ctx = getWorkingTurnContext(to); | ||
ensureRoomRecorded(to); | ||
return ctx.sendActivity(activity); | ||
} | ||
|
||
protected abstract void ensureRoomRecorded(TeamsAddressable to); | ||
|
||
private ConversationReference createConversationReference(TeamsAddressable address) { | ||
ConversationAccount ca = address == null ? null : getConversationAccount(address); | ||
|
||
|
84 changes: 84 additions & 0 deletions
84
...ain/java/org/finos/springbot/teams/conversations/StateStorageBasedTeamsConversations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.finos.springbot.teams.conversations; | ||
|
||
import static org.finos.springbot.teams.state.TeamsStateStorage.ADDRESSABLE_KEY; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import org.finos.springbot.entityjson.EntityJson; | ||
import org.finos.springbot.teams.content.TeamsAddressable; | ||
import org.finos.springbot.teams.content.TeamsChat; | ||
import org.finos.springbot.teams.history.StateStorageBasedTeamsHistory; | ||
import org.finos.springbot.teams.state.TeamsStateStorage; | ||
import org.finos.springbot.teams.state.TeamsStateStorage.Filter; | ||
import org.finos.springbot.workflow.content.Addressable; | ||
import org.finos.springbot.workflow.content.Chat; | ||
|
||
import com.microsoft.bot.builder.BotFrameworkAdapter; | ||
import com.microsoft.bot.connector.authentication.MicrosoftAppCredentials; | ||
import com.microsoft.bot.schema.ChannelAccount; | ||
|
||
public class StateStorageBasedTeamsConversations extends AbstractTeamsConversations { | ||
|
||
public static final String ADDRESSABLE_INFO = "addressable-info"; | ||
public static final String ADDRESSABLE_TYPE = "addressable-type"; | ||
public static final String CHAT = "chat"; | ||
public static final String USER = "user"; | ||
|
||
|
||
protected final TeamsStateStorage tss; | ||
|
||
public StateStorageBasedTeamsConversations(BotFrameworkAdapter bfa, MicrosoftAppCredentials mac, | ||
ChannelAccount botAccount, TeamsStateStorage tss) { | ||
super(bfa, mac, botAccount); | ||
this.tss = tss; | ||
} | ||
|
||
@Override | ||
public Set<Addressable> getAllAddressables() { | ||
List<Filter> filters = new ArrayList<>(); | ||
filters.add(new Filter(ADDRESSABLE_INFO)); | ||
Iterable<Map<String, Object>> it = tss.retrieve(filters, false); | ||
return new HashSet<>(StateStorageBasedTeamsHistory.findObjectsFromItems(Addressable.class, it)); | ||
} | ||
|
||
@Override | ||
public Set<TeamsChat> getAllChats() { | ||
List<Filter> filters = new ArrayList<>(); | ||
filters.add(new Filter(ADDRESSABLE_INFO)); | ||
filters.add(new Filter(ADDRESSABLE_TYPE, CHAT, "=")); | ||
Iterable<Map<String, Object>> it = tss.retrieve(filters, false); | ||
return new HashSet<>(StateStorageBasedTeamsHistory.findObjectsFromItems(TeamsChat.class, it)); | ||
} | ||
|
||
@Override | ||
public TeamsChat getExistingChat(String name) { | ||
return getAllChats().stream() | ||
.filter(tc -> tc.getName().equals(name)) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
|
||
@Override | ||
protected void ensureRoomRecorded(TeamsAddressable to) { | ||
String file = to.getKey()+"/addressable"; | ||
|
||
Optional<Map<String, Object>> data = tss.retrieve(file); | ||
|
||
if (!data.isPresent()) { | ||
Map<String, String> tags = new HashMap<>(); | ||
tags.put(ADDRESSABLE_INFO, TeamsStateStorage.PRESENT); | ||
tags.put(ADDRESSABLE_TYPE, to instanceof Chat ? CHAT : USER); | ||
tags.put(ADDRESSABLE_KEY, to.getKey()); | ||
EntityJson ej = new EntityJson(); | ||
ej.put(ADDRESSABLE_INFO, to); | ||
tss.store(file, tags, ej); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.